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