我有一個phpmailer表單,發送電子郵件完美罰款,但是我想發送每個表單提交2封電子郵件。第一封電子郵件應該是我自己的表單字段值。 Thsi按預期工作。我正在尋找任何可以讓我發送第二封電子郵件給提交表單的人的文件,以表示感謝與我們聯繫,我們將很快與他們聯繫。我基本上想發送第二封電子郵件給你的價值$_POST['email']
與「謝謝你」作爲內容。發送感謝您與phpmailer的電子郵件
形式的代碼(沒有任何謝謝郵箱):
require 'library/extensions/PHPMailerAutoload.php';
$mail = new PHPMailer;
$strMessage = "";
//Only action if the form has been submitted
if(isset($_POST['submit-contact-new'])) {
//Validate the fields again, because not everyone has Javascript, including bots
if (isset($_POST['name']) && $_POST['name'] !== "" &&
isset($_POST['surname']) && $_POST['surname'] !== "" &&
isset($_POST['email']) && $_POST['email'] !== "" &&
isset($_POST['phone']) && $_POST['phone'] !== "" &&
isset($_POST['comment']) && $_POST['comment'] !== "") {
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'mail.domain.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = '[email protected]'; // SMTP username
$mail->Password = 'passwd'; // SMTP password
$mail->From = '[email protected]';
$mail->FromName = 'Domain';
$mail->addAddress('[email protected]', 'First Last'); // Add a recipient
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Domain Form Enquiry';
$mail->Body = '
<html>
<body>
<h1>Domain Website Enquiry</h1>
<p>Information on form was:</p>
<p><strong>Name</strong>: '.$_POST['name'].'</p>
<p><strong>Surname</strong>: '.$_POST['surname'].'</p>
<p><strong>Email</strong>: '.$_POST['email'].'</p>
<p><strong>Phone</strong>: '.$_POST['phone'].'</p>
<p><strong>Enquiry</strong>: '.$_POST['comment'].'</p>
</body>
</html>
';
if(!$mail->send()) {
//Finally redirect
header('Location: '.$_SERVER['REQUEST_URI']. '?message='.$strMessage) ;
} else {
//Finally redirect
header('Location: http://domain.com/thank-you?location='.$strLocation) ;
}
} else {
//Something is wrong, so work out what
if (!isset($_POST['name']) || $_POST['name'] === "") $strMessage .= "<li>Name must be entered</li>";
if (!isset($_POST['surname']) || $_POST['surname'] === "") $strMessage .= "<li>Surname must be entered</li>";
if (isset($_POST['surname']) && isset($_POST['surname']) && $_POST['name'] === $_POST['surname']) $strMessage .= "<li>Name and Surname must be different</li>";
if (!isset($_POST['phone']) || $_POST['phone'] === "") $strMessage .= "<li>Phone Number must be entered</li>";
if (!isset($_POST['email']) || $_POST['email'] === "") $strMessage .= "<li>Email must be entered</li>";
if (!isset($_POST['comment']) || $_POST['comment'] === "") $strMessage .= "<li>An enquiry must be entered</li>";
if ($strMessage !== "") $strMessage = "<ul>" . $strMessage . "</ul>";
//Finally redirect
header('Location: '.$_SERVER['REQUEST_URI']. '?message='.$strMessage) ;
exit();
}
}
?>
添加這個** $ MAIL-> AddAddress($ _ POST [ '郵件']); ** **後$ MAIL-> addAddress('[email protected]」, '名姓'); ** – Noman
@Norman這會將相同的內容發送給雙方,而我希望向兩者發送不同的主體內容。謝謝 –
然後包裝你的代碼在功能和傳遞2參數1電子郵件和第二郵件正文。只需在這裏調用你的函數,使用參數傳遞不同的電子郵件和消息體。然後享受:) – Noman