我正在向两个不同的人发送邮件,两封不同的消息,一封给用户,一封给管理员。
$message1='hello user'
$message2='hello admin'
$email = '[email protected]'
$adminemail = '[email protected]';
require 'PHPMailerAutoload.php';
$mail = new PHPMailer(true);
$mail->isHTML();
$mail->IsSMTP();
$mail->setFrom('[email protected]', 'admin site');
$mail->AddAddress( $email);
$mail->Subject = $subject;
$mail->Body =$message1;
$mail->Send();
//message for admin
$mail->Body =$message2;
//$adminemail = $generalsettings[0]["admin_email"];
$mail->AddAddress($adminemail);
$mail->Send();
但是作为一个用户,我收到了两次消息..如何向两个不同的用户发送两条不同的消息。
哈姆雷特
I pray thee, do not mock me, fellow-student;
I think it was to see my mother's wedding.
霍雷肖
Indeed, my lord, it follow'd hard upon.
哈姆雷特
Thrift, thrift, Horatio! the funeral baked meats
Did coldly furnish forth the marriage tables.
Would I had met my dearest foe in heaven
Or ever I had seen that day, Horatio!
My father!--methinks I see my father.
霍雷肖
Where, my lord?
哈姆雷特
In my mind's eye, Horatio.
霍雷肖
I saw him once; he was a goodly king.
您可以启动两次 phpmailer 课程。
$message1='hello user'
$message2='hello admin'
$email = '[email protected]'
$adminemail = '[email protected]';
require 'PHPMailerAutoload.php';
$mail = new PHPMailer(true);
$mail->isHTML();
$mail->IsSMTP();
$mail->setFrom('[email protected]', 'admin site');
$mail->AddAddress($email);
$mail->Subject = $subject;
$mail->Body = $message1;
$mail->Send();
$mail2 = new PHPMailer(true);
$mail2->isHTML();
$mail2->IsSMTP();
$mail2->setFrom('[email protected]', 'admin site');
$mail2->AddAddress($adminemail);
$mail2->Subject = $subject;
$mail2->Body = $message2;
$mail2->Send();
这也应该有效:
$message1='hello user'
$message2='hello admin'
$email = '[email protected]'
$adminemail = '[email protected]';
require 'PHPMailerAutoload.php';
$mail = new PHPMailer(true);
$mail->isHTML();
$mail->IsSMTP();
$mail->setFrom('[email protected]', 'admin site');
$mail->AddAddress($email);
$mail->Subject = $subject;
$mail->Body = $message1;
$mail->Send();
$mail->ClearAddresses();
$mail->AddAddress($adminemail);
$mail->Body = $message2;
$mail->Send();
$mail->ClearAllRecipients();
// 它会删除旧电子邮件,发送旧电子邮件后使用此代码并再次使用 addaddress() 并向其他用户发送