我在通过PHP/IMAP发送电子邮件时遇到问题 - 我不知道是不是因为:
我的应用程序打开与电子邮件帐户的IMAP连接以读取收件箱中的邮件.它成功地做到了这一点 我遇到的问题是我想从此帐户发送邮件并将其显示在发件箱/已发送文件夹中.
据我所知,PHP imap_mail()函数不会以任何方式挂钩我当前打开的IMAP流.
我的代码执行时没有抛出错误.但是,电子邮件永远不会到达收件人,也不会显示在我发送的文件夹中.
private function createHeaders() {
return "MIME-Version: 1.0" . "\r\n" .
"Content-type: text/html; charset=iso-8859-1" . "\r\n" .
"From: " . $this->accountEmail . "\r\n";
}
private function notifyAdminForCompleteSet($urlToCompleteSet) {
$message = "
<p>
In order to process the latest records, you must visit
<a href='$urlToCompleteSet'>the website</a> and manually export the set.
</p>
";
try {
imap_mail(
$this->adminEmail,
"Alert: Manual Export of Records Required",
wordwrap($message, 70),
$this->createHeaders()
);
echo(" ---> Admin notified via email!\n");
}
catch (Exception $e) {
throw new Exception("Error in notifyAdminForCompleteSet()");
}
}
Run Code Online (Sandbox Code Playgroud)
我猜我需要手动将邮件复制到IMAP帐户中......或者这个问题有不同的解决方案吗?
此外,如果"from"地址中的域与运行此脚本的服务器上的域不同,这是否重要?我无法解释为什么邮件永远不会被发送.
imap_mail就像mail函数一样,它只是sendmail二进制文件的包装器.您最好通过普通的SMTP方式发送邮件(查看PHPMailer或Swift Mailer),然后让您的代码将消息放入带有imap_append的Sent文件夹中.
不知道是什么导致发送失败,但你应该检查imap_send代码中的布尔返回值.除此之外,您还需要检查SMTP服务器日志以获取任何线索.