我有一个联系表格,当用户提交所有价值时会发送(电子邮件)给admin.But现在我想做的时候用户提交管理员会收到电子邮件,用户也会收到一封电子邮件但不同的身体。
这是我之前的代码:
<?php
if(md5($verif_box).'a4xn' == $_COOKIE['tntcon']){
$name= $_POST["name"];
$email= $_POST["email"];
$phone= $_POST["phone"];
$company= $_POST["company"];
$message= $_POST["message"];
require_once('lib/class.phpmailer.php');
$mail = new PHPMailer(); // defaults to using php "mail()"
$mail->AddReplyTo("admin@gmail.com","I Concept");
$mail->SetFrom('admin@gmail.com', 'I Concept');
$mail->AddReplyTo("admin@gmail.com","I Concept");
$address = "admin@gmail.com";
$mail->AddAddress($address, "I Concept");
$mail->Subject = "MY - Request a Quote";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->Body = "<strong>Request a Quote from I Concept Malaysia Website</strong><br><br>
Name : $name<br>
Email : $email<br>
Phone : $phone<br>
Company : $company<br>
Enquiry : $message<br> <br>
Thank You!<br>
";
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!<br>";
}
}
?>
答案 0 :(得分:4)
尝试以下方法。没有测试,但您基本上需要另一个PHPMailer
对象,并分别设置body
和to
信息。
$address = "admin@gmail.com";
$mail->Subject = "MY - Request a Quote";
// keeps the current $mail settings and creates new object
$mail2 = clone $mail;
// mail to admin
$mail->AddAddress($address, "I Concept");
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->Body = "<strong>Request a Quote from I Concept Malaysia Website</strong><br><br>
Name : $name<br>
Email : $email<br>
Phone : $phone<br>
Company : $company<br>
Enquiry : $message<br> <br>
Thank You!<br>";
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!<br>";
}
// now send to user.
$mail2->AddAddress($email, $name);
$mail2->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail2->Body = "Separate email body for user filling form out.";
if(!$mail2->Send()) {
echo "Mailer Error: " . $mail2->ErrorInfo;
} else {
echo "Message sent!<br>";
}
答案 1 :(得分:1)
无需克隆PHPmailer对象。在更改正文并发送第二封电子邮件之前,只需使用PHPmailer中内置的ClearAllRecipients方法。
答案 2 :(得分:0)
我确定您无法在一次SMTP通话中发送不同的正文。但是,您只需发送第一封电子邮件并启动新的PHPMailer。