【发布时间】:2013-07-25 14:00:51
【问题描述】:
我正在尝试使用phpmailer 向多个用户发送邮件。
我正在做的是:
a) 首先输入以逗号分隔的email id,让用户输入:test@test.com,test1@test.com
b) 将它们分解成数组:
$email_list = $_POST['emailid'];
$email_array = explode(',',$email_list);
c) 现在的 email 数组就像
array('0'=>'test@test.com','1'=>'test1@test.com')
d) 使用 phpmailer 使用 foreach 循环发送邮件如下:
foreach($email_array as $email_array )
{
$email = $email_array;
//die;
include('notification/class.phpmailer.php');
$subject = $_POST['subject'];
$body = $_POST['content'];
$smtphost = get_option('smtphostlord');
$smtpportlord = get_option('smtpportlord');
$smtpemailord = get_option('smtpemailord');
$smtppasslord = get_option('smtppasslord');
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = $smtphost; // SMTP server
$mail->SMTPDebug = 1; // enables SMTP debug information (for testing)// 1 = errors and messages , // 2 = messages only
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = $smtphost; // sets GMAIL as the SMTP server
$mail->Port = $smtpportlord; // set the SMTP port for the GMAIL server
$mail->Username = $smtpemailord; // GMAIL username
$mail->Password = $smtppasslord; // GMAIL password
$mail->Subject = $subject;
$mail->MsgHTML($body);
echo $email;
$mail->AddAddress($email); // sending email to
echo $mail->Send();
$wpdb->query("insert into `sendmail_lordlinus`(`id`,`email`,`subject`,`body`,`sent`) values('','$email','$subject','$body','1')");
}
但是当我尝试从前端发送邮件时,它只会将邮件发送到第一个电子邮件 ID 和 die the code,而不会出现任何错误:
我在这段代码中缺少什么?
谢谢
【问题讨论】:
-
你不应该把
include变成一个循环;)