donglu8344812 2012-03-01 03:00
浏览 38
已采纳

如何与多个收件人和不同的身体进行电子邮件表格?

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("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>";
}


}
?>
  • 写回答

3条回答 默认 最新

  • dongshixingga7900 2012-03-01 03:14
    关注

    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 = "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>";
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 telegram 问题
  • ¥15 nrf52810-c三个a 程序
  • ¥15 lego-loam跑出来的roll误差很大
  • ¥50 求一个半透明没有锯齿的圆角窗体的实现例子
  • ¥15 STM32cubeMX里的FreeRTOS无法释放内存
  • ¥15 CATIA有些零件打开直接单机确定终止
  • ¥15 请问有会的吗,用MATLAB做
  • ¥15 phython如何实现以下功能?查找同一用户名的消费金额合并—
  • ¥15 孟德尔随机化怎样画共定位分析图
  • ¥18 模拟电路问题解答有偿速度