如何使用phpmailer将电子邮件发送到多个地址 [英] how to send emails to multiple addresses using phpmailer

查看:138
本文介绍了如何使用phpmailer将电子邮件发送到多个地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用php mailer将电子邮件发送到多个电子邮件地址,但无法正常工作.我试过爆炸地址,但似乎无济于事.这是我的代码

I am trying to send emails to multiple email addresses using php mailer but its not working. I've tried explode the addresses but nothing seems to work. here is my code

html:

<input type="text" name="addresses" value="{$addresses}"/>

输入中的当前输出为test1 @ gmail.com,test2 @ gmail.com,test3 @ gmail.com,

current output in the input is test1@gmail.com,test2@gmail.com,test3@gmail.com,

php发送电子邮件:

php to send email:

/* Get Customer info*/
$sql = mysql_query("SELECT * FROM customer WHERE ID='$id' LIMIT 1");
$sql=mysql_fetch_array($sql);
$fname=$sql['FIRST_NAME'];
$lname=$sql['LAST_NAME'];
$company=$sql['COMPANY'];
$customer_email=$sql['EMAIL'];

$email_addresses=$VAR['addresses'];

if($email_addresses != "" && $customer_email !=""){    
$emailto=$email_addresses;            
}elseif($email_addresses == "" && $customer_email !=""){
$emailto=$customer_email; 
} 

/* Get Email Options */
$r=mysql_query("SELECT * FROM `email` WHERE `ID`=1");
$r=mysql_fetch_array($r);
$emailfrom=$r['EMAIL_FROM'];
$emailpriority=$r['EMAIL_PRIORITY'];
$emailsubject=$r['EMAIL_SUBJECT'];

/* Headers */
$subject = "$emailsubject";
$mailer = "$emailfrom";
$headers = "From: $mailer \r\n";
$headers .= "Reply-To: $mailer\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n boundary=\"PHP-mixed-    ".$random_hash."\"";
$headers .= "Importance: $emailpriority\r\n";

$email = new PHPMailer();
$email->From      = $mailer;
$email->FromName  = $mailer;
$email->Subject   = $subject;
$email->Body      = $message; 
$email->AddAddress( $emailto );
$email->isHTML(true);

$email->Send();

因此,如果我在输入框中有一个收件人,它将很好地发送电子邮件,但是如果我有多个收件人并将其与分开,它将不会发送电子邮件.我试过$ emailto = explode(',',$ email_addresses);由于我使用分隔电子邮件,但这不起作用.任何建议都会很棒.

so if I have one recipient in the input box it send the email fine but if I have multiple and separate them with , it does not send the email. i've tried $emailto=explode(',',$email_addresses); since I am separating the email with , but that does not work. any suggestion would be great.

推荐答案

假定$ email_addresses变量中包含良好的数据.

Assume you have good data in $email_addresses variable.

您需要更改行:

$email->AddAddress( $emailto );

进入:

$addr = explode(',',$email_addresses);

foreach ($addr as $ad) {
    $email->AddAddress( trim($ad) );       
}

这篇关于如何使用phpmailer将电子邮件发送到多个地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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