Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Sendmail not working, using mail() in PHP

Posted on 2004-10-28
12
Medium Priority
?
2,224 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
Comment
Question by:Thesolitas
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
12 Comments
 
LVL 2

Author Comment

by:Thesolitas
ID: 12435978
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 62

Expert Comment

by:gheist
ID: 12442170
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
ID: 12446325
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 62

Expert Comment

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

Author Comment

by:Thesolitas
ID: 12454914
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 62

Accepted Solution

by:
gheist earned 1000 total points
ID: 12455801
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
ID: 12489047
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
ID: 12489347
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 62

Expert Comment

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

Author Comment

by:Thesolitas
ID: 12500079
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 62

Expert Comment

by:gheist
ID: 12533908
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
ID: 12541468
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Suggested Courses

598 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