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 = "recipient@example.com";
    $subject = "Nonsensical Latin";
    
    // compose headers
    $headers = "From: sender@myVirtualSite.com\r\n";
    $headers .= "Reply-To: sender@myVirtualSite.com\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 www-data@myISPconfigSite.com  Fri Aug 24 09:37:12 2007
    Return-Path: <www-data@myISPconfigSite.com>
    X-Original-To: recipient@example.com
    Delivered-To: recipient@example.com
    Received: by server1.sdellis.com (Postfix, from userid 33)
            id DBCA63588001; Fri, 24 Aug 2007 09:37:12 -0500 (CDT)
    To: recipient@example.com
    Subject: Nonsensical Latin
    From: sender@myVirtualSite.com
    Reply-To: sender@myVirtualSite.com
    X-Mailer: PHP/5.1.6
    Message-Id: <20070824142812.DBCA63588001@server1.myISPconfigSite.com>
    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=<20070824143754.48BE63588001@server1.myISPconfigSite.com>
    Aug 24 09:37:54 postfix/qmgr[28463]: 48BE63588001: from=<www-data@myISPconfigSite.com>, size=661, nrcpt=1 (queue active)
    Aug 24 09:37:54 postfix/local[5895]: 48BE63588001: to=<recipient@example.com>, 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:
    <someuser@verizon.net>: 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; www-data@server1.myISPconfigSite.com
    Arrival-Date: Sat,  4 Aug 2007 17:20:50 +0000 (UTC)
    
    Final-Recipient: rfc822; someuser@verizon.net
    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

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

Share This Page