0

好吧,我得到了这段代码,它可以工作,但是我需要将每个循环都设置为 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 不会改变每个循环。

4

2 回答 2

0

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

于 2012-10-01T02:25:57.453 回答
0

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

我希望这有帮助。请让我知道你发现了什么。

于 2012-10-01T02:43:50.083 回答