如何发送两个不同的消息给两个不同的用户phpmailer [英] how to send two different messages to two different users phpmailer

查看:106
本文介绍了如何发送两个不同的消息给两个不同的用户phpmailer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将邮件发送给两个不同的人,两条不同的消息,一条给用户,一条给管理员.

I am sending mails to two different persons, two different messages one for user and one for admin.

  $message1='hello user'      
  $message2='hello admin'
  $email = 'user@email.com'
  $adminemail = 'admin@email.com';

  require 'PHPMailerAutoload.php';
  $mail = new PHPMailer(true);
  $mail->isHTML();
  $mail->IsSMTP(); 
  $mail->setFrom('admin@mysite.com', '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();

但是作为一个用户,我两次收到该消息.如何向两个不同的用户发送两个不同的消息.

But as a user I am receiving the message twice.. How to send two different messages to two different users.

推荐答案

在添加第二封邮件的新地址之前,您需要清除收件人列表.如果您不这样做,则第一个收件人也会收到第二条消息:

You need to clear the recipients list before you add the new address for the second message. If you don't do that, the first recipient will receive the second message as well:

...
$mail->Body     =$message1;
$mail->Send();

//message for admin 

// Remove previous recipients
$mail->ClearAllRecipients();
// alternative in this case (only addresses, no cc, bcc): 
// $mail->ClearAddresses();

$mail->Body     =$message2;
//$adminemail = $generalsettings[0]["admin_email"]; 

// Add the admin address
$mail->AddAddress($adminemail);
$mail->Send();

这篇关于如何发送两个不同的消息给两个不同的用户phpmailer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆