重用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/>"; }

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...