Configure PHP with Haraka mail server

380 views Asked by At

I have a script like that :

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

I installed and configured the mail server haraka. I think that my configuration is ok : When I use the command swaks -tls -f [email protected] -t [email protected] -s localhost -p 587 -au testuser -ap testpassword, i receive correctly the mail.

But when I send a mail via the mail function in PHP, I don't receive anything.

In my php.ini, I configure :

;[mail function]
SMTP = localhost
smtp_port = 587
username = testuser
password = testpassword
sendmail_from = [email protected]

After script's execution, when I check haraka's logs, I don't see anything. But in the file /var/log/maillog, I can see that sendmail's logs are adds.

Can you tell me how o configure PHP to use correctly my local mail server Haraka ?

1

There are 1 answers

2
ABDELJALIL AIT ETALEB On

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

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

read docs for more information