Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
521 views
in Technique[技术] by (71.8m points)

php - How to do email form with multiple recipients and different body?

i have one contact form, when user submit all value will send(email) to admin.But now i want to do when user submit admin will receive the email and user also will receive an email but with different body.

here my previous code :

<?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("[email protected]","I Concept");

$mail->SetFrom('[email protected]', 'I Concept');

$mail->AddReplyTo("[email protected]","I Concept");

$address = "[email protected]";
$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>";
}


}
?>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try the following. Didn't test but you basically need to get another PHPMailer object going and set the body and to information separately.

$address = "[email protected]";
$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>";
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...