Friday, January 14, 2011

Trouble sending an email with the PHP mail function. Full trace provided

I have a simple script setup:

<?php
mail('corgan1003@aol.com', 'Hello World', 'Testing a message');
?>

I cannot send email from my server to AOL accounts. The error details are below. GMail lets me send the message...so I guess AOL is just a bit stricter.

   Starting tcpick 0.2.1 at 2009-08-03 22:25 UTC
    Timeout for connections is 600
    tcpick: reading from tcp_dump.pcap
    1      SYN-SENT       67.23.28.65:49516 > 64.12.138.153:smtp
    1      SYN-RECEIVED   67.23.28.65:49516 > 64.12.138.153:smtp
    1      ESTABLISHED    67.23.28.65:49516 > 64.12.138.153:smtp
    220-rly-mg05.mx.aol.com ESMTP mail_relay_in-mg05.6; Mon, 03 Aug 2009 18:25:34 -0400
    220-America Online (AOL) and its affiliated companies do not
    220-     authorize the use of its proprietary computers and computer
    220-     networks to accept, transmit, or distribute unsolicited bulk
    220-     e-mail sent from the internet.  Effective immediately:  AOL 
    220-     may no longer accept connections from IP addresses which 
    220      have no reverse-DNS (PTR record) assigned.
    EHLO bandop.com
    250-rly-mg05.mx.aol.com fallsroadsunoco.com
    250 HELP
    MAIL FROM:<www-data@com>
    501 SYNTAX ERROR IN PARAMETERS OR ARGUMENTS
    RSET
    250 OK
    QUIT
    1      FIN-WAIT-1     67.23.28.65:49516 > 64.12.138.153:smtp
    2      SYN-SENT       67.23.28.65:45729 > 216.239.113.101:smtp
    1      FIN-WAIT-2     67.23.28.65:49516 > 64.12.138.153:smtp
    221 SERVICE CLOSING CHANNEL
    1      RESET          67.23.28.65:49516 > 64.12.138.153:smtp
    3      SYN-SENT       67.23.28.65:45729 > 216.239.113.101:smtp
    tcpick: done reading from tcp_dump.pcap

    20 packets captured
    3 tcp sessions detected

Do you know how I can make the FROM parameter come out correctly? Setting the FROM header in the PHP mail function does not work.

UPDATE

This little hack is working but I would prefer to fix this issue outside of PHP.

mail('corgan1003@aol.com', 'Hello World', 'Testing a message', null,'-faddress@domain.com');

I am super noob with mail servers

  • With AOL they often won't go through unless you fill out the form to get white listed. To change where the mail is coming from, edit the sendmail_path parameter in the php.ini file. This is mentioned in the php mail() doc under additional_parameters.

    For Example:

    sendmail_path = "/usr/sbin/sendmail -t -f me@kyle.com"
    

    You can also pass instead a parameter to the mail() function:

    <?php
    mail('nobody@example.com', 'the subject', 'the message', null,
       '-fwebmaster@example.com');
    ?>
    

    Lastly, you might find alternative mail package more flexible, such as PEAR MAIL package or msmtp, you can specify other smtp servers.

    Tony : right now i am using phpmailer because the site is wordpress based and it comes stock. only issue is i have to change a wordpress file to create this setting which is bad practice. i would like to know how to fix this in postfix settings. it would be great to have postfix use the virtual host name as a host as well.
  • Try escaping the at sign.

    mail('corgan1003\@aol.com', 'Hello World', 'Testing a message');
    
  • You want to change the envelope From: address, which is different from the From: header. See this comment in the mail() function's doc.

    The envelope address depends on your MTAs configuration - in your case, 'www-data' is the user your script runs as, and 'com' is (part?) of your machine's hostname. Assuming you are on *nix, you can try to override the envelope address like this:

    mail('corgan1003@aol.com', 'Hello World', 'Testing a message', null,'-faddress@domain.com');
    

    where address@domain.com is the envelope sender address you want to show.

    If that works, and you have access to your php.ini file, you can set the envelope sender address there - see Kyle's post.

    You might also want to have a look at your MTAs (sendmail, postfix) configuration - looks like it has a problem with your hostname setting. Changing php-s settings will fix it for php, but if something else (cron, logwatch) on your system wants to sent mail, it would be helpful to have a working MTA.

    Edit after your comment: It's hard to suggest anything without knowing your mail server's config, but for a start, try the following:

    myhostname = mail.virtualhostname.com
    mydomain = virtualhostname.com
    myorigin = $mydomain
    masquerade_domains = virtualhostname.com
    
    Tony : yes, i would rather fix this for postfix and not just PHP. the postfix configuration file is huge though. all i really want is the FROM field to be "noreply@virtualhostname.com". I set myorigin = $mydomain but that did nothing. Maybe you could provide some direction?
    Tony : my mail server's config is the default postfix installation. i haven't done anything fancy. adding these attributes to the config does not seem to change the envelope's FROM address

0 comments:

Post a Comment