2

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

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 = test@mydomain.com

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 ?

Julien
  • 200
  • 1
  • 15

1 Answers1

2

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