3
我有一個php web表單,我試圖用聯繫我們頁面。除了能夠將成功提交的內容發送到多個電子郵件地址之外,一切都按預期工作。我已經試過如下:PHP表單提交到多個電子郵件
$targetEmail = '[email protected]', '[email protected]';
以及把$ targetEmail在數組中:
$targetEmail = array(
'Email1' => '[email protected]',
'Email1' => '[email protected]',
);
但它永遠不會提交到兩個地址。任何建議將不勝感激。
完整的代碼可以在下面
<?php
\t //****************************************
\t //edit here
\t $senderName = 'Contact Form';
\t $senderEmail = '[email protected]';
\t $targetEmail = '[email protected]';
\t $messageSubject = 'Contact Us Form';
\t $redirectToReferer = false;
\t $redirectURL = 'http://www.website.com/thankyou.html';
\t //****************************************
\t // mail content
\t $name = $_POST['name'];
\t $email = $_POST['email'];
\t // prepare message text
\t $messageText = \t 'Name: '.$name."\n".
\t \t \t \t \t 'Email: '.$email."\n";
\t // send email
\t $senderName = "=?UTF-8?B?" . base64_encode($senderName) . "?=";
\t $messageSubject = "=?UTF-8?B?" . base64_encode($messageSubject) . "?=";
\t $messageHeaders = "From: " . $senderName . " <" . $senderEmail . ">\r\n"
\t \t \t \t . "MIME-Version: 1.0" . "\r\n"
\t \t \t \t . "Content-type: text/plain; charset=UTF-8" . "\r\n";
\t if (preg_match('/^[_.0-9a-z-][email protected]([0-9a-z][0-9a-z-]+.)+[a-z]{2,4}$/',$targetEmail,$matches))
\t mail($targetEmail, $messageSubject, $messageText, $messageHeaders);
\t // redirect
\t if($redirectToReferer) {
\t \t header("Location: "[email protected]$_SERVER['HTTP_REFERER'].'#sent');
\t } else {
\t \t // header("Location: ".$redirectURL);
\t \t header("Location: http://www.website.com/thankyou.html");
\t }
?>
'$ targetEmail = '[email protected],[email protected]';' –