$mail->Send() 使用 PHPMailer 发送多封邮件 class
$mail->Send() send multiple email using PHPMailer class
using PHPMailer class.
I have following code. for email send to client and owner same email,
only Send from information is change for client and owner.
Blockquote
when i submit email information ,client get double email(get 2 email) and owner get 1 email.
and client get email from client information how can send individual
email to both.
is this code contain any error?
/* for client email send*/
$emailAddr ='owneremail@gmail.com';
$body = $client_message;
$body = eregi_replace("[\]",'',$body);
$mail->SetFrom(c, $name);
$mail->AddAddress($_POST['email'], $_POST['name']);
$mail->Subject = "subject1";
$mail->MsgHTML($body);
$mail->AddAttachment("images/download.pdf");
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
}
/*For owner email*/
$client_message1 = $client_message;
$body = $client_message1;
$body = eregi_replace("[\]",'',$body);
$mail->SetFrom($_POST['email'], $_POST['name']);
$mail->AddAddress($emailAddr, $name);
$mail->Subject = "subject1";
$mail->MsgHTML($body);
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
}
注意: 由于您没有在问题中提及,我假设您使用的是 PHPMailer class。用这些信息更新问题是个好主意。
AddAddress()函数,顾名思义,向收件人列表添加个新地址,同时保持以前添加的地址。
解法:
在为第 $mail->AddAddress($emailAddr, $name);
[= 行添加第二封电子邮件的收件人地址之前,您必须使用 clearAllRecipients() 函数39=]。该部分的最终代码应如下所示:
$mail->clearAllRecipients();
$mail->AddAddress($emailAddr, $name);
那里还提到了许多其他类似的有用功能。请检查。另外,看看这个 question 和答案。它将帮助您更深入地了解问题。
希望我的回答对您有所帮助。
using PHPMailer class. I have following code. for email send to client and owner same email, only Send from information is change for client and owner. Blockquote when i submit email information ,client get double email(get 2 email) and owner get 1 email. and client get email from client information how can send individual email to both. is this code contain any error?
/* for client email send*/
$emailAddr ='owneremail@gmail.com';
$body = $client_message;
$body = eregi_replace("[\]",'',$body);
$mail->SetFrom(c, $name);
$mail->AddAddress($_POST['email'], $_POST['name']);
$mail->Subject = "subject1";
$mail->MsgHTML($body);
$mail->AddAttachment("images/download.pdf");
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
}
/*For owner email*/
$client_message1 = $client_message;
$body = $client_message1;
$body = eregi_replace("[\]",'',$body);
$mail->SetFrom($_POST['email'], $_POST['name']);
$mail->AddAddress($emailAddr, $name);
$mail->Subject = "subject1";
$mail->MsgHTML($body);
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
}
注意: 由于您没有在问题中提及,我假设您使用的是 PHPMailer class。用这些信息更新问题是个好主意。
AddAddress()函数,顾名思义,向收件人列表添加个新地址,同时保持以前添加的地址。
解法:
在为第 $mail->AddAddress($emailAddr, $name);
[= 行添加第二封电子邮件的收件人地址之前,您必须使用 clearAllRecipients() 函数39=]。该部分的最终代码应如下所示:
$mail->clearAllRecipients();
$mail->AddAddress($emailAddr, $name);
那里还提到了许多其他类似的有用功能。请检查。另外,看看这个 question 和答案。它将帮助您更深入地了解问题。
希望我的回答对您有所帮助。