在 php 文件中,我需要向 2 个不同的 ID 发送 2 封不同的电子邮件。当我使用如下所示的两个变量时,它不起作用。
require 'PHPmailer/class.phpmailer.php';
/* First Email*/
$email = new PHPMailer();
$email->From = '[email protected] /cdn-cgi/l/email-protection';
$email->FromName = 'My Webisite';
$email->Subject = 'Subject of first email';
$email->Body = 'Body of the message to first person';
$email->AddAddress( 'to first person' );
$file_to_attach = 'path of the file';
$email->AddAttachment( $file_to_attach, '' );
$email->Send();
/* Second Email*/
require 'PHPmailer/class.phpmailer.php';
$confirm = new PHPMailer();
$confirm-> From = '[email protected] /cdn-cgi/l/email-protection';
$confirm-> FromName = 'Admin @ MyWebsite';
$confirm-> Subject = 'Subject of second email';
$confirm-> Body = 'Body of second email';
$confirm-> AddAddress('Email ID of second person');
$confirm->Send();
但是如果我使用同一个变量两次,我将按如下所示工作
require 'PHPmailer/class.phpmailer.php';
/* First Email*/
$email = new PHPMailer();
/* Same as above*/
$file_to_attach = 'path of the file';
$email->AddAttachment( $file_to_attach, '' );
$email->Send();
/* Second Email*/
$email-> From = '[email protected] /cdn-cgi/l/email-protection';
$email-> FromName = 'Admin @ MyWebsite';
$email-> Subject = 'Subject of second email';
$email-> Body = 'Body of second email';
$email-> AddAddress('Email ID of second person');
$email->Send();
但问题是它正在将附件发送到两个电子邮件 ID。请帮助我如何不将附件发送到第二个 ID。
unset($mail->attachment)
不会像attachment
is a 受保护的多变的。而是使用:
$email->clearAttachments();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)