1

我正在尝试使用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没有任何错误:

我在这段代码中缺少什么?

谢谢

4

2 回答 2

1

将您的第一行更新为

foreach($email_array as $email )

并删除应该变得无用的以下行:

$email = $email_array;

于 2013-07-25T14:07:23.040 回答
1

我得到了我的解决方案。我只是将include()语句放在foreach循环之上,它对我有用

于 2013-07-25T14:08:00.730 回答