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) 次のように foreach ループを使用して phpmailer を使用してメールを送信します。

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 に答える