【问题标题】:unable to send mail to multiple person in phpmailer无法在phpmailer中向多个人发送邮件
【发布时间】: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 变成一个循环;)

标签: php ssl phpmailer


【解决方案1】:

将您的第一行更新为

foreach($email_array as $email )

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

$email = $email_array;

【讨论】:

  • 如果在循环之前执行包含会怎样?
  • 这只是我无法弄清楚。我在想办法,一有答案我会第一时间联系你的
【解决方案2】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-25
    • 1970-01-01
    • 2019-01-19
    相关资源
    最近更新 更多