简体   繁体   English

使用Haraka邮件服务器配置PHP

[英]Configure PHP with Haraka mail server

I have a script like that : 我有一个像这样的脚本:

<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>

I installed and configured the mail server haraka. 我安装并配置了邮件服务器haraka。 I think that my configuration is ok : When I use the command swaks -tls -f test@mydomain.com -t foo@mydomain.com -s localhost -p 587 -au testuser -ap testpassword , i receive correctly the mail. 我认为我的配置还可以:当我使用命令swaks -tls -f test@mydomain.com -t foo@mydomain.com -s localhost -p 587 -au testuser -ap testpassword ,我正确地收到了邮件。

But when I send a mail via the mail function in PHP, I don't receive anything. 但是,当我通过PHP中的mail函数发送邮件时,我什么也没收到。

In my php.ini , I configure : 在我的php.ini ,我配置:

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

After script's execution, when I check haraka's logs, I don't see anything. 脚本执行后,当我检查haraka的日志时,我什么都看不到。 But in the file /var/log/maillog , I can see that sendmail's logs are adds. 但是在文件/var/log/maillog ,我可以看到sendmail的日志已添加。

Can you tell me how o configure PHP to use correctly my local mail server Haraka ? 您能告诉我如何配置PHP以正确使用本地邮件服务器Haraka吗?

it would not work with php's mail function , try to work with this instead to Send messages over SMTP PHPMailer or swiftMailer , check this too 它不适用于php的邮件功能,请尝试与此功能一起通过SMTP PHPMailerswiftMailer发送消息,也请进行此检查

    //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!';
   }
   ?>

read docs for more information 阅读文档以获取更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM