1

php mail return false when i run mail function

here is my code

$to = 'xxxxxx@gmail.com';
$subject = 'Login';
$message = 'Thanks for Login ! Your account has been logged on website.';
$headers = 'From:xxxxx@gmail.com' . "\r\n";
var_dump(mail($to, $subject, $message, $headers));

when i opened mail log there is no error found and when i test to send mail over ubuntu terminal using this command

echo "Test mail from postfix" | mail -s "Test Postfix" you@example.com

it sends to me mail correctly

also i configured php.ini

sendmail_path = /usr/sbin/sendmail -t -i -f care@mydomain.com

2 Answers2

0

first try this one: use this code make a Connection

    <html>

   <head>
      <title>Sending HTML email using PHP</title>
   </head>

   <body>

      <?php
         $to = "xyz@somedomain.com";
         $subject = "This is subject";

         $message = "<b>This is HTML message.</b>";
         $message .= "<h1>This is headline.</h1>";

         $header = "From:abc@somedomain.com \r\n";
         $header .= "Cc:afgh@somedomain.com \r\n";
         $header .= "MIME-Version: 1.0\r\n";
         $header .= "Content-type: text/html\r\n";

         $retval = mail ($to,$subject,$message,$header);

         if( $retval == true ) {
            echo "Message sent successfully...";
         }else {
            echo "Message could not be sent...";
         }
      ?>

   </body>
</html>
Karthi
  • 528
  • 1
  • 5
  • 16
0

I had this issue, but in my case it was due to my postfix configuration being quite restrictive. I found this error in /var/log/maillog:

postfix/sendmail[pid]: fatal: User apache(id) is not allowed to submit mail

The fix was to add "apache" to the main.cf:

authorized_submit_users = root spamd apache

Then, don't forget to restart postfix

systemctl restart postfix