尝试发送2封邮件时PHPMailer失败

时间:2017-03-19 15:30:47

标签: php file email phpmailer

我正在尝试一次发送两封不同的邮件。 1封电子邮件只是文本,另一封邮件带有附件。

我尝试了两种不同的方法来处理这个问题。 我的第一次尝试是拥有2个文件。一个向客户发送邮件。另一页发送邮件给我们。我的第二次尝试是尝试合并到一个页面。

我将首先尝试用2个不同的页面尝试我的第一次尝试。

在表单验证成功并插入我的数据库后,我将它们包括在内:

include_once './mailklant.php';
include_once './mailsp.php';

mailklant.php代码是(SMTP连接已删除,但效果很好。):

//Set the subject line
$mail->Subject = 'To customer: Your order ' . toxInput::get('po');
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->msgHTML('Hello '. $toxUser->data()->fullname . ',<br>Your order '. toxInput::get('po'));
//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';

if (!$mail->send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
}

mailsp.php看起来像这样:

//Set the subject line
$mail->Subject = 'To us: Klant: #KLANTNAAM# heeft een nieuwe order geplaatst <> ' . toxInput::get('po');
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->msgHTML('Beste,<br>' . $toxUser->data()->fullname . ' heeft een nieuwe order geplaatst voor #KLANTNAAM#.');
//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';
//die($_SERVER["DOCUMENT_ROOT"] . 'spoos/data/testdata/'. toxInput::get('po').'.xlsx');
$mail->addAttachment($_SERVER["DOCUMENT_ROOT"] . '/spoos/data/testdata/'. toxInput::get('po').'.xlsx');

if (!$mail->send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
}

问题是。 mailklant.php成功运行但mailsp.php无效。甚至没有错误回来。我只收到一封邮件。 当我在die('test');的第2行添加mailsp.php时。当我运行脚本时,它返回test,因此页面包含在内。 BTW excel文件也是有效的,并且是文件的正确路径。它将在我的第二次尝试中证明。

我的第二次尝试是将这两个文件合并为一个:

//Set the subject line
$mail->Subject = 'To customer: Your order ' . toxInput::get('po');
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->msgHTML('Hello '. $toxUser->data()->fullname . ',<br>Your order '. toxInput::get('po'));
//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';

if (!$mail->send()) {
   echo "Mailer Error: " . $mail->ErrorInfo;
}

$mail->Subject = 'To us: Klant: #KLANTNAAM# heeft een nieuwe order geplaatst <> ' . toxInput::get('po');
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->msgHTML('Beste,<br>' . $toxUser->data()->fullname . ' heeft een nieuwe order geplaatst voor #KLANTNAAM#.');
//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';
//die($_SERVER["DOCUMENT_ROOT"] . 'spoos/data/testdata/'. toxInput::get('po').'.xlsx');
$mail->addAttachment($_SERVER["DOCUMENT_ROOT"] . '/spoos/data/testdata/'. toxInput::get('po').'.xlsx');

if (!$mail->send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
}

然后我收到3封电子邮件。一个给客户,没有excel文件。 2次给我们,包括excel文件。

当我试图使用它时:

$mail->ClearAllRecipients();
$mail->ClearReplyTos();
$mail->ClearCustomHeaders();
$mail->setFrom('', '');
//Set an alternative reply-to address
$mail->addReplyTo('', '');
//Set who the message is to be sent to
$mail->addAddress('', '');

我还收到3封邮件。 1对客户,2次给我们。

0 个答案:

没有答案
相关问题