DoppyNL
asked on
PHP5 WinXP Mail SMTP Failure because of an unknown reason
Hi all,
I've got a problem when I try to send out an email.
It seems that PHP or something else is messing up the to-header and thus the smtp server doesn't know what to do with it.
Configuration:
WindowsXP Professional
IIS SMTP Server (also tried my ISP's smtp)
PHP5.0.2
Apache 2.something
Headers that I'm sending out:
[code]Message-ID: <20041026111124DoppyMailer @validdoma in.ext>
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Doppy Server Mailer
From: "Source adress" <doppy@validdomain.ext>
To: "doppy@validdomain.ext" <doppy@validdomain.ext>; "doppynl@validdomain2.ext" <doppy@validdomain2.ext>
CC: "doppy@validdomain.ext2" <doppy@validdomain.ext2>
Subject: Just Testing again...
Return-Path: <bounce@validdomain.ext>
testmessage[/code]
note: I replaced the names with the adres to find out if that solved it, it didn't.
The error:
Warning: mail() [function.mail]: SMTP server response: 501 5.5.4 Invalid Address in D:\ServerHTTP\Internal\sto rage\class es\email.p hp on line 50
When I leave out the CC-header the message is:
Warning: mail() [function.mail]: SMTP server response: 503 No recipient(s). in D:\ServerHTTP\Internal\sto rage\class es\email.p hp on line 50
PHP.ini configuration is set to use the smtpserver on localhost default port.
Anyone got any idea what is going on here??
I've got a problem when I try to send out an email.
It seems that PHP or something else is messing up the to-header and thus the smtp server doesn't know what to do with it.
Configuration:
WindowsXP Professional
IIS SMTP Server (also tried my ISP's smtp)
PHP5.0.2
Apache 2.something
Headers that I'm sending out:
[code]Message-ID: <20041026111124DoppyMailer
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Doppy Server Mailer
From: "Source adress" <doppy@validdomain.ext>
To: "doppy@validdomain.ext" <doppy@validdomain.ext>; "doppynl@validdomain2.ext"
CC: "doppy@validdomain.ext2" <doppy@validdomain.ext2>
Subject: Just Testing again...
Return-Path: <bounce@validdomain.ext>
testmessage[/code]
note: I replaced the names with the adres to find out if that solved it, it didn't.
The error:
Warning: mail() [function.mail]: SMTP server response: 501 5.5.4 Invalid Address in D:\ServerHTTP\Internal\sto
When I leave out the CC-header the message is:
Warning: mail() [function.mail]: SMTP server response: 503 No recipient(s). in D:\ServerHTTP\Internal\sto
PHP.ini configuration is set to use the smtpserver on localhost default port.
Anyone got any idea what is going on here??
Could you post the complete code including the actual mail function?
Keep in mind that the mail function takes the to adresses as the first argument, the To: in the headers might not be enough to make it work properly. Example:
$subject = "About this";
$message = "Message text";
$headers = "To: ToAddress <to@address.com>, To2 <to2@address.com>\r\n";
$headers.= "CC: CCAddress <cc@address.com\r\n";
etc
mail("to@address.com, to2@address.com", $subject, $message, $headers);
Keep in mind that the mail function takes the to adresses as the first argument, the To: in the headers might not be enough to make it work properly. Example:
$subject = "About this";
$message = "Message text";
$headers = "To: ToAddress <to@address.com>, To2 <to2@address.com>\r\n";
$headers.= "CC: CCAddress <cc@address.com\r\n";
etc
mail("to@address.com, to2@address.com", $subject, $message, $headers);
ASKER
I'm creating my own headers and passing them to the mail function.
when I do something like this:
mail('valid@adress.ext','n ormal-test 2','messag e');
it is send and received without a hitch.
Since a plain use of the mail function seems to work, there must be something wrong with my headers....
The code responsible for sending the email:
$headers = 'Message-ID: <' . strftime('%Y%m%d%H%M%S') . uniqueid() . 'DoppyMailer@validdomain.e xt>' . "\n";
$headers .= 'X-Priority: 3' . "\n";
$headers .= 'X-MSMail-Priority: Normal' . "\n";
$headers .= 'X-Mailer: Doppy Server Mailer' . "\n";
$headers .= 'From: ' . $this->source . "\n";
$headers .= 'To: ' . implode('; ', $this->to) . "\n";
if (count($this->cc) > 0)
{
$headers .= 'CC: ' . implode('; ', $this->cc) . "\n";
}
if (count($this->bcc) > 0)
{
$headers .= 'BCC: ' . implode('; ', $this->bcc) . "\n";
}
$headers .= 'Subject: ' . $this->subject . "\n";
$headers .= 'Return-Path: <' . self::bounceadress . '>' . "\n";
return(mail('', '', $this->message, $headers));
$this->to, $this->cc and $this->bcc are arrays with items that look like:
"name of person" <adres@ofperson.ext>
I allready posted an example of the resulting $headers variable in my previous post.
Anyone of you see my mistake in here somewhere?
when I do something like this:
mail('valid@adress.ext','n
it is send and received without a hitch.
Since a plain use of the mail function seems to work, there must be something wrong with my headers....
The code responsible for sending the email:
$headers = 'Message-ID: <' . strftime('%Y%m%d%H%M%S') . uniqueid() . 'DoppyMailer@validdomain.e
$headers .= 'X-Priority: 3' . "\n";
$headers .= 'X-MSMail-Priority: Normal' . "\n";
$headers .= 'X-Mailer: Doppy Server Mailer' . "\n";
$headers .= 'From: ' . $this->source . "\n";
$headers .= 'To: ' . implode('; ', $this->to) . "\n";
if (count($this->cc) > 0)
{
$headers .= 'CC: ' . implode('; ', $this->cc) . "\n";
}
if (count($this->bcc) > 0)
{
$headers .= 'BCC: ' . implode('; ', $this->bcc) . "\n";
}
$headers .= 'Subject: ' . $this->subject . "\n";
$headers .= 'Return-Path: <' . self::bounceadress . '>' . "\n";
return(mail('', '', $this->message, $headers));
$this->to, $this->cc and $this->bcc are arrays with items that look like:
"name of person" <adres@ofperson.ext>
I allready posted an example of the resulting $headers variable in my previous post.
Anyone of you see my mistake in here somewhere?
ASKER
@KvdnBerg:
When I change this line:
return(mail('', '', $this->message, $headers));
to:
return(mail(implode('; ', $this->to), '', $this->message, $headers));
and leave the rest as it is I get the exact same error.
If it then also comment out the To: line in the headers I also get the same error message.
When I change this line:
return(mail('', '', $this->message, $headers));
to:
return(mail(implode('; ', $this->to), '', $this->message, $headers));
and leave the rest as it is I get the exact same error.
If it then also comment out the To: line in the headers I also get the same error message.
Make sure that each header ends with \r\n. Windows especially is picky this way. Also, I would recommend changing the implode statements to use a comma instead of a semicolon altough I don't think that is really the problem.
ASKER
replacing \n with \r\n didn't help (was probably trying that when you were typing your message! :P )
replacing ; with , as a seperator also didn't help.
replacing ; with , as a seperator also didn't help.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Problem solved:
- mail function overrides the "to" and "subject" of your own headers with what you pass along to the function. So you must set the to-header and the subject-header in the mail-function, not in your own headers. Other headers do work normally.
- mail function does NOT understand this format at all:
"person name" <person@adress.ext>
this doesn't work for to, cc or bcc. instead just use:
person@adress.ext
Problem solved; tnx all for digging in the problem.
Accepting the correct answer.
- mail function overrides the "to" and "subject" of your own headers with what you pass along to the function. So you must set the to-header and the subject-header in the mail-function, not in your own headers. Other headers do work normally.
- mail function does NOT understand this format at all:
"person name" <person@adress.ext>
this doesn't work for to, cc or bcc. instead just use:
person@adress.ext
Problem solved; tnx all for digging in the problem.
Accepting the correct answer.
I know that this is not a solution, but just wanted some more information. How does your code look?