Problems with PHP mail() function

Discussion in 'Installation/Configuration' started by stirfry, Aug 24, 2007.

  1. stirfry

    stirfry New Member

    Sorry in advance for the long post, but I want to make sure I include all relevant info.

    I've been using one of the webmail apps (UebiMiau) that comes with ISPConfig and it works just fine. However, I'm having two different problems with using the PHP mail() function on my websites at IP addresses which are different from the IP that ISPConfig runs on. These two problems may or may not be related to each other, so I'll describe them both here just in case.

    The first problem has to do with the way mail is handled when I do a simple test with the PHP mail() function. I run this script from one of my virtual sites (email addresses changed to protect against SPAM):

    Code:
    <?php
    $to = "[email protected]";
    $subject = "Nonsensical Latin";
    
    // compose headers
    $headers = "From: [email protected]\r\n";
    $headers .= "Reply-To: [email protected]\r\n";
    $headers .= "X-Mailer: PHP/".phpversion();
    
    // compose message
    $message = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit.";
    $message .= " Nam iaculis pede ac quam. Etiam placerat suscipit nulla.";
    $message .= " Maecenas id mauris eget tortor facilisis egestas.";
    $message .= " Praesent ac augue sed enim aliquam auctor. Ut dignissim ultricies est.";
    $message .= " Pellentesque convallis tempor tortor. Nullam nec purus.";
    $message = wordwrap($message, 70);
    
    // send email
    mail($to, $subject, $message, $headers);
    ?>

    After running it, I always get new mail in my system mailbox (/var/mail/shaun ... not /var/mail/www-data). This is what it says:


    Code:
    From [email protected]  Fri Aug 24 09:37:12 2007
    Return-Path: <[email protected]>
    X-Original-To: [email protected]
    Delivered-To: [email protected]
    Received: by server1.sdellis.com (Postfix, from userid 33)
            id DBCA63588001; Fri, 24 Aug 2007 09:37:12 -0500 (CDT)
    To: [email protected]
    Subject: Nonsensical Latin
    From: [email protected]
    Reply-To: [email protected]
    X-Mailer: PHP/5.1.6
    Message-Id: <[email protected]>
    Date: Fri, 24 Aug 2007 09:37:12 -0500 (CDT)
    
    Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nam iaculis
    pede ac quam. Etiam placerat suscipit nulla. Maecenas id mauris eget
    tortor facilisis egestas. Praesent ac augue sed enim aliquam auctor.
    Ut dignissim ultricies est. Pellentesque convallis tempor tortor.
    Nullam nec purus.

    My mail.log:

    Code:
    Aug 24 09:37:54 postfix/pickup[1329]: 48BE63588001: uid=33 from=<www-data>
    Aug 24 09:37:54 postfix/cleanup[5893]: 48BE63588001: message-id=<[email protected]>
    Aug 24 09:37:54 postfix/qmgr[28463]: 48BE63588001: from=<[email protected]>, size=661, nrcpt=1 (queue active)
    Aug 24 09:37:54 postfix/local[5895]: 48BE63588001: to=<[email protected]>, relay=local, delay=0.04, delays=0.02/0.01/0/0.01, dsn=2.0.0, status=sent (delivered to command: procmail -a "$EXTENSION")
    Aug 24 09:37:54 postfix/qmgr[28463]: 48BE63588001: removed
    As you can see from the above log output, the status is "sent", but I can't tell if it's bouncing back or if it's going directly into my system mailbox.


    I think I understand what's going on with my second problem, but I don't know how to fix it. One another site (at a different IP), I'm using HTML Mime Mail (http://www.phpguru.org/static/htmlMimeMail5.html) and I keep seeing messages in the www-data system user's mailbox that look like this:


    Code:
    <[email protected]>: host relay.verizon.net[206.46.232.11] said: 550
        5.1.8 invalid/host-not-in-DNS return address not allowed (in reply to MAIL
        FROM command)
    
    --ED2F45D9076.1186248055/server1.myISPconfigSite.com
    Content-Description: Delivery report
    Content-Type: message/delivery-status
    
    Reporting-MTA: dns; server1.myISPconfigSite.com
    X-Postfix-Queue-ID: ED2F45D9076
    X-Postfix-Sender: rfc822; [email protected]
    Arrival-Date: Sat,  4 Aug 2007 17:20:50 +0000 (UTC)
    
    Final-Recipient: rfc822; [email protected]
    Action: failed
    Status: 5.1.8
    Remote-MTA: dns; relay.verizon.net
    Diagnostic-Code: smtp; 550 5.1.8 invalid/host-not-in-DNS return address not
        allowed
    
    --ED2F45D9076.1186248055/server1.myISPconfigSite.com
    Content-Description: Undelivered Message
    Content-Type: message/rfc822

    I have 3 public IP's. One IP is for an e-commerce site which requires SSL, the other IP is for ISPConfig/my site, and the last IP is for virtual hosting of basic PHP-enabled web sites. I assume that webmail works because webmail sends from the ISPConfig IP and passes the DNS lookup test, but when mail is sent from PHP scripts running at a different IP, it fails the DNS lookup and bounces back.

    Does anyone know how I can fix this so the PHP mail() function works AND passes the host/DNS test?
     
  2. falko

    falko Super Moderator Howtoforge Staff

    You can try to bind Postfix to one IP address with the smtp_bind_address parameter.
     

Share This Page