【问题标题】:Configure PHP with Haraka mail server使用 Haraka 邮件服务器配置 PHP
【发布时间】:2019-03-07 14:32:28
【问题描述】:

我有一个这样的脚本:

<html>
<body>

<?php

$addresses = ['foo@mydomain.com'];

foreach ($addresses as $address) {
        sendMail($address);?><br /><?php
}
?>

<?php

        function sendMail($address) {
                mail($address, "object", "message");
                print $address;
        }

?>

</body>
</html>

我安装并配置了邮件服务器haraka。我认为我的配置没问题:当我使用命令swaks -tls -f test@mydomain.com -t foo@mydomain.com -s localhost -p 587 -au testuser -ap testpassword 时,我可以正确收到邮件。

但是当我通过 PHP 中的邮件功能发送邮件时,我什么也收不到。

在我的php.ini 中,我配置:

;[mail function]
SMTP = localhost
smtp_port = 587
username = testuser
password = testpassword
sendmail_from = test@mydomain.com

脚本执行后,当我检查 haraka 的日志时,我什么也没看到。但是在/var/log/maillog文件中,我可以看到sendmail的日志被添加了。

你能告诉我如何配置 PHP 以正确使用我的本地邮件服务器 Haraka 吗?

【问题讨论】:

    标签: php email smtp haraka


    【解决方案1】:

    它不适用于 php 的邮件功能,请尝试使用它来通过 SMTP PHPMailerswiftMailer 发送消息,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 = 'test@domain.com';
       $mail->Password = 'EMAIL_ACCOUNT_PASSWORD';
       $mail->setFrom('test@domain.com', 'Your Name');
       $mail->addReplyTo('reply-box@domain.com', 'Your Name');
       $mail->addAddress('example@gmail.com', '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!';
       }
       ?>
    

    阅读文档了解更多信息

    【讨论】:

    • 请不要添加仅链接的答案。
    • 我只是想发表评论,但我不能,因为我必须有 50 个声望
    猜你喜欢
    • 2018-08-15
    • 1970-01-01
    • 1970-01-01
    • 2011-03-12
    • 1970-01-01
    • 2018-04-14
    • 1970-01-01
    • 2016-09-28
    • 2015-08-02
    相关资源
    最近更新 更多