Home > Enterprise >  mail() PHP always use [email protected] domain and my server reject each mail
mail() PHP always use [email protected] domain and my server reject each mail

Time:05-04

mail function of my php scripts always use user@localdomain in the from header. As a result my new SMTP relay provider bounce the mail becouse the localdomain isn't resolvable. This is an example script:

<html>

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

   <body>

      <?php
         $to = "[email protected]";
         $subject = "This is subject";

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

         $header = "From:[email protected] \r\n";
         $header .= "Cc:[email protected] \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>

This is the postfix log:

May  2 21:14:39 pabx postfix/qmgr[7436]: 835F710995D: from=<[email protected]>, size=664, nrcpt=1 (queue active)
May  2 21:14:39 pabx sendmail[14995]: 242JEdJk014995: [email protected], ctladdr=asterisk (1001/1001), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=30254, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (Ok: queued as 835F710995D)
May  2 21:14:39 pabx postfix/smtpd[14996]: disconnect from localhost[127.0.0.1]
May  2 21:14:39 pabx postfix/smtp[15000]: 835F710995D: to=<[email protected]>, relay=127.0.0.1[127.0.0.1]:10111, delay=0.32, delays=0.09/0.02/0.18/0.03, dsn=5.1.0, status=bounced (host 127.0.0.1[127.0.0.1] said: 550 5.1.0 lbVHne6ItQDqNlbVHnYS2C invalid domain (in reply to MAIL FROM command))
May  2 21:14:39 pabx postfix/cleanup[14999]: D577A109991: message-id=<[email protected]>
May  2 21:14:39 pabx postfix/bounce[15002]: 835F710995D: sender non-delivery notification: D577A109991
May  2 21:14:39 pabx postfix/qmgr[7436]: D577A109991: from=<>, size=2641, nrcpt=1 (queue active)
May  2 21:14:39 pabx postfix/qmgr[7436]: 835F710995D: removed
May  2 21:14:40 pabx postfix/smtp[15000]: D577A109991: to=<[email protected]>, relay=127.0.0.1[127.0.0.1]:10111, delay=0.25, delays=0/0/0.17/0.08, dsn=5.1.1, status=bounced (host 127.0.0.1[127.0.0.1] said: 550 5.1.1 lbVHne6J4QDqNlbVInYS2E pabx.lan2 dominio non valido / invalid destination domain (in reply to RCPT TO command))
May  2 21:14:40 pabx postfix/qmgr[7436]: D577A109991: removed

CodePudding user response:

Open /etc/hosts

Try to add your domain between 127.0.0.1 and rest of entries

The mail server picks up the first entry

So if you set for example:

127.0.0.1 exampledomain.com servername localhost localhost.localdomain ...

As well you can check if your smtp server its using the proper host name.

CodePudding user response:

I solved the problem using this library instead. https://github.com/PHPMailer/PHPMailer

  • Related