微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

重用PHPMailer发送第二封电子邮件?

我正在开发一个订购系统,需要向客户,经销商和网站所有者发送电子邮件.

所有者和经销商可以获得相同的电子邮件(订单详细信息等),但客户需要一个略有不同的主体,以包含感谢信息.

目前我有这个:

require_once('PHPMailer/class.PHPmailer.PHP');
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 0; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'tls'; // secure transfer enabled required for GMail
$mail->Host = "";
$mail->Port = 587; // or 587
//$mail->IsHTML(true);
$mail->Username = "";
$mail->Password = "";
$mail->SetFrom("");
$mail->IsHTML(true);
$mail->Subject = "Online Shop - New Order - " . $orderNumber;
$mail->Body = "A new order has been placed with Online Shop. Please find the delivery details below: <br><br> " . $orderDetails;
$mail->AddAddress($distributerEmail); //distributor email address
$mail->AddAddress($ownerEmail); //Owner email address
if($mail->Send()){  }else{ $error = "Error sending message! <br/>"; }

如何重用$mail组件,发送另一封电子邮件而不必定义服务器详细信息?一世

解决方法:

试试这个:

require_once 'PHPMailerAutoload.PHP';
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 0; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'tls'; // secure transfer enabled required for GMail
$mail->Host = "";
$mail->Port = 587; // or 587
//$mail->IsHTML(true);
$mail->Username = "";
$mail->Password = "";
$mail->SetFrom("");
$mail->IsHTML(true);
$mail->Subject = "Online Shop - New Order - " . $orderNumber;
$mail->Body = "A new order has been placed with Online Shop. Please find the delivery details below: <br><br> " . $orderDetails;
$mail->AddAddress($distributerEmail); //distributor email address
$mail->AddAddress($ownerEmail); //Owner email address
if($mail->Send()){  }else{ $error = "Error sending message! <br/>"; }

// We delete the addresses of distributer and owner.
$mail->Clearaddresses();

$mail->AddAddress($customerEmail);
$mail->Body = "new body";

if($mail->Send()){  }else{ $error = "Error sending message! <br/>"; }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐