重用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/>"; }
上一篇:PHPmail函数中的“无法访问文件:”


下一篇:C语言程序设计做题笔记之C语言基础知识(上)