Solved

Sendmail not working, using mail() in PHP

Posted on 2004-10-28
2,085 Views
Last Modified: 2013-11-22
I'm trying to get the mail() function in PHP working, which uses sendmail on my freebsd box. I'm pretty sure the PHP code is fine as I've used this exact script on a couple other boxes.

I've tested using sendmail from the console, and it worked fine. I receieved the message quickly, no errors, etc. But whenever I try using the mail command, I'm getting an error in /var/log/maillog , it says among other stuff "Invalid route address", here's the complete log.

sendmail[1256]: i9RMVj09001256: from=www, size=3324, class=0, nrcpts=1, msgid=<200410272231.i9RMVj09001256@DOMAIN.COM>, relay=www@localhost

sendmail[1256]: i9RMVj09001256: i9RMVj0A001256: DSN: EMAILADDRESS1, EMAILADDRESS2... Invalid route address

sm-mta[1257]: i9RMVjUr001257: from=<>, size=5160, class=0, nrcpts=1, msgid=<200410272231.i9RMVj0A001256@DOMAIN.COM>,
proto=ESMTP, daemon=Daemon0, relay=localhost [127.0.0.1]

sendmail[1256]: i9RMVj0A001256: to=www, delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=34348, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (i9RMVjUr001257 Message accepted for delivery)

sm-mta[1258]: i9RMVjUr001257: to=webmaster, ctladdr=<www@DOMAIN.COM> (26/0), delay=00:00:00, mailer=local, pri=125160, dsn=5.1.1, stat=User unknown

sm-mta[1258]: i9RMVjUr001257: i9RMVjUr001258: postmaster notify: User unknown

sm-mta[1258]: i9RMVjUr001258: to=root, delay=00:00:00, xdelay=00:00:00, mailer=local, pri=36391, relay=local, dsn=2.0.0, stat=Sent

sendmail[1256]: i9RMVj09001256: i9RMVj0A001256: DSN: EMAILADDRESS1, EMAILADDRESS2... Invalid route address

Note: I've removed the email addresses and domain names.

If you need any other information (config information, tests done, etc. just ask), all I need is to be able to send mail out using the mail function through PHP.
0
Question by:Thesolitas
    12 Comments
     
    LVL 2

    Author Comment

    by:Thesolitas
    ACK: I duplicated a line from the log, the last log line:

    sendmail[1256]: i9RMVj09001256: i9RMVj0A001256: DSN: EMAILADDRESS1, EMAILADDRESS2... Invalid route address

    Shouldn't be there, it should only be there once near the top (2nd line).
    0
     
    LVL 60

    Expert Comment

    by:gheist
    The problem is that addresses without @ and those @localhost are quite illegal, and next wrong thing about your mailserver is that you removed mail alias for postmaster, so you do not get any mail errors.
    0
     
    LVL 2

    Author Comment

    by:Thesolitas
    This server is a dedicated server setup by a hosting company.

    I didn't remove any alias's from the sendmail config, so I'm not sure why the postermaster alias wouldn't be there, but I can fix that.

    As far as the @ and @localhost addresses, what would cause that?

    I'm setting a from address when I use the php mail command, and this worked on two other box's of mine. The from address is for a domain that is hosted on this box.
    0
     
    LVL 60

    Expert Comment

    by:gheist
    Do these contain @ : EMAILADDRESS1, EMAILADDRESS2 ???
    0
     
    LVL 2

    Author Comment

    by:Thesolitas
    Yes, EMAILADDRESS1 and EMAILADDRESS2 are valid email address's. I replaced them with that as I didn't want them in the message.
    0
     
    LVL 60

    Accepted Solution

    by:
    what does
    dig -t mx domain1 show ???
    then - is dig -t a <what it showed> showing some legal IP address ???
    0
     
    LVL 2

    Author Comment

    by:Thesolitas
    Okay, I see there's a problem there, it seems the domain it's trying to send the mail out as is the main domain tied to the box. Here's the thing.

    The box has multiple domains on it. I'm only using 1 currently (the one I'm trying to send mail out as), but it's not the domain the box is setup under.

    If I check (using "dig -t mx domain") the domain I WANT to send mail out under, it's all fine. It's not fine for the main box domain though.

    I'll fix the domain the box is setup with, but I'd still like to be able to send mail out using the proper domain. I'm not sure why it's not sending the mail out under the proper domain, it did on my other box. I'm guessing it's either the sendmail setup in my php.ini, or something I need to do differently with my mail command in my script.

    Thanks for the help! If you have any thoughts as to why it would be sending out mail under the wrong domain they would be appreciated. Thanks again.
    0
     
    LVL 2

    Author Comment

    by:Thesolitas
    Ahh, finally fixed it.

    My php script for mailing was using the Cc header to copy a couple additional people on the message. I guess when I originally grabbed the code for this, it was using a semi-colon to seperate the names in the Cc header field. This worked on my other boxes, but not on this one. I found using a comma fixed the problem.

    So this whole thing was failing because it didn't like the ; instead of the , in the Cc field. :\

    Anyways, thanks for your help ghieist, it helped me narrow down where I was looking which ultimately led to me finding the problem, so thanks again.
    0
     
    LVL 60

    Expert Comment

    by:gheist
    Srtangest thing is that SMTP does not care much about what is put inside mail DATA
    0
     
    LVL 2

    Author Comment

    by:Thesolitas
    Well I tried both from PHP using the mail function, and from the console using sendmail directly.

    If I use a semi-colon to seperate the addresses in the Cc, or the To fields, instead of a comma, I get errors in my maillog saying:

    DSN: email@domain.com, email2@domain.com... Invalid route address

    It's odd, as this doesn't happen on my other machine, but I just read somewhere that though semi-colons are supported in alot of software, the RFC says comma's are the required seperator and that semicolons are not officially supported. I'm going to take a look through the RFC's and see if this is really the case.
    0
     
    LVL 60

    Expert Comment

    by:gheist
    what makes you think mail() in php can accept multiple destinations???

    http://si.php.net/manual/en/function.mail.php
    0
     
    LVL 2

    Author Comment

    by:Thesolitas
    Well it does, cause I have it working now. And I've had it working prior to this.

    In their example #4 they even describe it:

    /* recipients */
    $to  = "mary@example.com" . ", " ; // note the comma
    $to .= "kelly@example.com";

    The original code I grabbed for using the mail function though used a semicolon, not a comma, and that's where some versions of sendmail have problems. Some seem to accept a semi-colon seperating the To, CC, and BCC fields, some don't.
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT Security CISA, CISSP & CISM Certification

    Master the advanced techniques required to protect network resources from external threats with the IT Cyber Security bundle. Built around industry best-practice guidelines, the IT Cyber Security bundle consists of three in-depth courses.

    Hello fellow BSD lovers, I've created a patch process for patching openjdk6 for BSD (FreeBSD specifically), although I tried to keep all BSD versions in mind when creating my patch. Welcome to OpenJDK6 on BSD First let me start with a little …
    In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
    Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
    Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

    913 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now