我正在尝试使用 phpmailer
向多个用户发送邮件。
我正在做的是:
a) 首先输入以逗号分隔的电子邮件 ID,让用户输入:test@test.com,test1@test.com
b) 将它们分解成数组:
$email_list = $_POST['emailid'];
$email_array = explode(',',$email_list);
c) 现在电子邮件数组就像
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
没有任何错误:
这段代码中缺少什么?
谢谢
更新你的第一行
foreach($email_array 作为 $email )
并删除以下应该变得无用的行:
$email = $email_array;
我是一名优秀的程序员,十分优秀!