PHPMailer , keep 1 SMTP Connection with different receiver by email content

浪子不回头ぞ 提交于 2020-01-03 02:59:09

问题


$phpMailer = New PHPMailer();
$phpMailer->isSMTP();
$phpMailer->SMTPKeepAlive = true;

for ( ... ) {
    // Send your emails right away
    [ ... ]
}

$phpMailer->SmtpClose();

HI, I have an example code for KeepAlive SMTP here, but my problem is I send email with difference contents to my users. So each user have 1 content.

Can I do it like this:

 for ( ... ) {
       $phpMailer->addAddress($user['email'], $user['name']);
       $phpMailer->Subject = $user['subject'];
       $phpMailer->Body = $user['body'];
       $phpMailer->Send()
    }

Will the ->addAddress increase my recipients every time on the loop? Or will it clean the old recipient after ->send() comitted ?


回答1:


Call clearAddresses() Before addAddress function . It is cleared before recipients.

$phpmailer->ClearAddresses();
$phpMailer->addAddress($user['email'], $user['name']);


来源:https://stackoverflow.com/questions/18283541/phpmailer-keep-1-smtp-connection-with-different-receiver-by-email-content

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!