我正在尝试使用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
发送邮件而没有任何错误:
我在这段代码中缺少什么?
由于
答案 0 :(得分:1)
将您的第一行更新为
foreach($email_array as $email )
并删除以下应该变得无用的行:
$email = $email_array;
答案 1 :(得分:1)
我得到了解决方案。我只是将include()
语句放在foreach
循环之上,它对我有用