我正在使用PHPMailer从公司内部的 stmp 服务器发送电子邮件通知。电子邮件已成功发送,但未存储在Outlook上的已发送邮件文件夹中。
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
require 'phpmailer/vendor/autoload.php';
$mail = new PHPMailer(true);
try {
$mail->SMTPDebug = SMTP::DEBUG_SERVER;
$mail->isSMTP();
$mail->Host = 'smtpinternal.xxxx.com';
$mail->SMTPAuth = false;
$mail->SMTPAutoTLS = false;
$mail->Username = 'xxxxnoreply@xxxx.com';
$mail->Password = 'xxxx';
$mail->Port = 25;
$mail->setFrom('xxxxnoreply@xxxx.com', 'xxxx_NoReply');
$distributionLists = explode(',', $items['Distribution List']);
foreach ($distributionLists as $distributionList) {
if (!empty($distributionList) && strpos( $distributionList, '@' ) !== false ) {
$mail->addAddress(trim($distributionList)); }
}
$contacts = explode(',', $items['Contact']);
foreach ($contacts as $contact) {
if (!empty($contact) && strpos( $contact, '@' ) !== false ) {
$mail->addCC(trim($contact)); }
}
$mail->isHTML(true);
$mail->Subject = 'Invoice Report';
$mail->Body = "Dear Client, <br><br> Please find below today's invoices <br><br>". $table ."<br> Please contact your representative on Email address : ". $items['Contact'] ."<br><br> Best regards. <br><br> Please do not reply to this message, as it has been sent by a system email address.";
$mail->send();
$mail_string = $mail->getSentMIMEMessage();
$path = "{".$mail->Host.":25/imap/ssl/novalidate-cert}";
$imapStream = imap_open($path, $mail->Username, $mail->Password);
imap_append($ImapStream, $path, $mail_string, "\\Seen");
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}"; }
?>
imap_open函数返回以下错误:
imap_open(): Couldn't open stream {smtpinternal.xxxx.com:25/imap/ssl/novalidate-cert}
我尝试更新$path
到
{"imap.smtpinternal.xxxx.com:25/imap/ssl/novalidate-cert}
或者{smtpinternal.xxxx.com:25/imap/ssl/authuser=xxxxnoreply@xxxx.com}
但仍然得到同样的错误。有什么建议请我应该如何声明我的路径变量以指向Outlook中的已发送邮件文件夹?谢谢你。