PHPMailer在以下代码中只发送一个附件,但我想要多个附件

时间:2017-08-08 12:40:12

标签: php phpmailer email-attachments

以下是我的代码 包括(" Phpmailer.php&#34);

$phpmail = new PHPMailer();
$phpmail->Mailer = 'mail';
$phpmail->Host = 'relay-hosting.secureserver.net';
$phpmail->ClearAddresses();
$phpmail->ContentType = 'text/html';
$phpmail->From = "from@mail.com";
$phpmail->FromName = "Company";
$phpmail->Sender = "from@mail.com";
$phpmail->AddAddress("to@mail.com","Test user");
$phpmail->Subject = 'Multiple Attachment';
$mailBoddy = file_get_contents("files/example_text_file.txt");
$arrayFind = array("{ABC}","{XYZ}");
$arrayReplace = array("Test","Multiple Attachment");
$mailBoddy = str_replace($arrayFind,$arrayReplace,$mailBoddy);
$phpmail->Body = $mailBoddy;
// attachment
$phpmail->AddAttachment("files/example1.pdf","Example 1");
$phpmail->AddAttachment("files/example2.pdf","Example 2");

// send email
if(!$phpmail->Send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $phpmail->ErrorInfo;
} else {
    echo 'Message has been sent';
};

问题在于,在上面的代码中,它只发送一个附件,这是第一个示例1,不包括第二个附件。我想发送多个文件,如" example1"和" example2"在单个电子邮件中。

0 个答案:

没有答案