使用php邮件使用多个用户名和密码发送多个电子邮件?

时间:2012-10-01 01:57:10

标签: php

嗯,我得到了这个代码,它可以工作,但我需要设置每个循环PHPMailer,如果它是好的idk但如果我不设置它每个循环从不改变总是来我设置的第一个,看起来:

foreach($this->users as $v)
{   
    $this->phpmailer = new PHPMailer();

    $this->phpmailer->IsSMTP();
    $this->phpmailer->SMTPAuth = true;
    $this->phpmailer->SMTPSecure = 'ssl';

    $this->phpmailer->Host = 'smtp.gmail.com';
    $this->phpmailer->Port = 465;

    $this->phpmailer->ClearAllRecipients();
    $this->phpmailer->AddAddress($v['email']);

    $this->phpmailer->Username = $v['email_user'];
    $this->phpmailer->Password = $v['email_pass'];

    $this->phpmailer->From = $v['email_user'];
    $this->phpmailer->FromName = $v['email_name'];

...

它可以工作,但我每次循环都设置PHPMailer但是如果我这样做:

$this->phpmailer = new PHPMailer();

$this->phpmailer->IsSMTP();
$this->phpmailer->SMTPAuth = true;
$this->phpmailer->SMTPSecure = 'ssl';

$this->phpmailer->Host = 'smtp.gmail.com';
$this->phpmailer->Port = 465;

foreach($this->users as $v)
{       
    $this->phpmailer->ClearAllRecipients();
    $this->phpmailer->AddAddress($v['email']);

    $this->phpmailer->Username = $v['email_user'];
    $this->phpmailer->Password = $v['email_pass'];

    $this->phpmailer->From = $v['email_user'];
    $this->phpmailer->FromName = $v['email_name'];

...

它会起作用但是from不会改变每个循环。

2 个答案:

答案 0 :(得分:0)

我没有为您提供解决方案,但希望与PHPMailer分享我的经验:我必须为我发送的每封邮件创建一个全新的对象,以获得我想要的结果,即使电子邮件相同但有不同的收件人。

答案 1 :(得分:0)

很难说。错误报告是否设置为显示所有错误?是什么从phpMailer失败?这不太可能,但我刚刚看到一个类似的问题,其中运行对象循环污染了日志并阻止脚本正确执行。

我希望这会有所帮助。请告诉我你的发现。