我有一个这样的脚本:
<html>
<body>
<?php
$addresses = ['[email protected]'];
foreach ($addresses as $address) {
sendMail($address);?><br /><?php
}
?>
<?php
function sendMail($address) {
mail($address, "object", "message");
print $address;
}
?>
</body>
</html>
我安装并配置了邮件服务器haraka。我认为我的配置没问题:当我使用命令swaks -tls -f [email protected] -t [email protected] -s localhost -p 587 -au testuser -ap testpassword
时,我收到了正确的邮件。
但是当我通过PHP中的邮件功能发送邮件时,我什么都收不到。
在我的php.ini
中,我配置:
;[mail function]
SMTP = localhost
smtp_port = 587
username = testuser
password = testpassword
sendmail_from = [email protected]
脚本执行后,当我查看haraka的日志时,我什么都没看到。但在文件/var/log/maillog
中,我可以看到sendmail的日志是添加的。
你能告诉我如何配置PHP以正确使用我的本地邮件服务器Haraka?
它不适用于PHP的邮件功能,尝试使用此代替通过SMTP发送邮件PHPMailer或swiftMailer,check this too
//PHPMailer
<?php
use PHPMailer\PHPMailer\PHPMailer;
require 'vendor/autoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Host = 'localhost';
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->Username = '[email protected]';
$mail->Password = 'EMAIL_ACCOUNT_PASSWORD';
$mail->setFrom('[email protected]', 'Your Name');
$mail->addReplyTo('[email protected]', 'Your Name');
$mail->addAddress('[email protected]', 'Receiver Name');
$mail->Subject = 'PHPMailer SMTP message';
$mail->msgHTML(file_get_contents('message.html'), __DIR__);
$mail->AltBody = 'This is a plain text message body';
$mail->addAttachment('test.txt');
if (!$mail->send()) {
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message sent!';
}
?>
阅读文档以获取更多信息