mail() Incorrect Address Format when using IIS7/FastCGI
mail() Incorrect Address Format when using IIS7/FastCGI
am 29.01.2008 17:57:31 von Dan Richfield
When using IIS7 with PHP 5.2.5 with the FastCGIModule, the mail()
function returns the following error message when trying to use anything
but a plain email address (ex. test@test.com) in the From or To
headers:
PHP Warning: mail() [function.mail]: SMTP server response: 501 Incorrect
Address Format
If you use a plain email address it works fine. An example of what
causes this problem is as follows:
Test
The problem is that PHP is formatting the header incorrectly but adding
additional < and > tags around the entire address. This is illustrated
in this excerpt from my mail server log:
16:28:05.79 5 SMTPI-39353([XXX.XXX.XXX.XXX]) inp: MAIL FROM:
>
With a plain email address, it still adds the < and > tags, but it
works. Here is an example of that from the mail server log:
16:28:21.72 5 SMTPI-39408([XXX.XXX.XXX.XXX]) inp: MAIL
FROM:
Also, this same behavior was reported in Bug #28038 but I have confirmed
that this is error does not occurs when using this same PHP version in
CGI mode with IIS7. That tells me this bug was fixed, but has reoccured
in 5.2.5 with FastCGI.
Reproduce code:
---------------
$To = "dan@easycgi.com";
$Subject = "Test";
$Body = "Test";
$Headers = "From: Test User " . "\r\n";
mail($To, $Subject, $Body, $Headers);
print "mail sent!";
?>
Expected result:
----------------
True result
Actual result:
--------------
PHP Warning: mail() [function.mail]: SMTP server response: 501 Incorrect
Address Format
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: mail() Incorrect Address Format when using IIS7/FastCGI
am 29.01.2008 19:01:40 von Manuel Lemos
Hello,
on 01/29/2008 02:57 PM Dan Richfield said the following:
> When using IIS7 with PHP 5.2.5 with the FastCGIModule, the mail()
> function returns the following error message when trying to use anything
> but a plain email address (ex. test@test.com) in the From or To
> headers:
>
> PHP Warning: mail() [function.mail]: SMTP server response: 501 Incorrect
> Address Format
>
> If you use a plain email address it works fine. An example of what
> causes this problem is as follows:
>
> Test
>
> The problem is that PHP is formatting the header incorrectly but adding
> additional < and > tags around the entire address. This is illustrated
> in this excerpt from my mail server log:
>
> 16:28:05.79 5 SMTPI-39353([XXX.XXX.XXX.XXX]) inp: MAIL FROM:
> >
>
> With a plain email address, it still adds the < and > tags, but it
> works. Here is an example of that from the mail server log:
>
> 16:28:21.72 5 SMTPI-39408([XXX.XXX.XXX.XXX]) inp: MAIL
> FROM:
It seems like a bug.
If you are stuck, you may want to try this package that comes with a
mail() replacement function written in pure PHP named smtp_mail(). It
works like mail but it overcomes certain limitations. Take a look at the
test_smtp_mail.php example script.
http://www.phpclasses.org/mimemessage
You also need this for the delivery:
http://www.phpclasses.org/smtpclass
--
Regards,
Manuel Lemos
PHP professionals looking for PHP jobs
http://www.phpclasses.org/professionals/
PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: mail() Incorrect Address Format when using IIS7/FastCGI
am 29.01.2008 19:13:28 von Dan Richfield
I have already posted it to bugs.php.net
(http://bugs.php.net/bug.php?id=43730) and php is claiming it's not a bug.
Thanks for your suggestion, but I have to use mail because this is being
offered to shared hosting customers and a mass scale. Most applications and
developers use the mail() function.
Thanks,
Dan
"Manuel Lemos" wrote in message
news:479F6A04.3080806@acm.org...
> Hello,
>
> on 01/29/2008 02:57 PM Dan Richfield said the following:
>> When using IIS7 with PHP 5.2.5 with the FastCGIModule, the mail()
>> function returns the following error message when trying to use anything
>> but a plain email address (ex. test@test.com) in the From or To
>> headers:
>>
>> PHP Warning: mail() [function.mail]: SMTP server response: 501 Incorrect
>> Address Format
>>
>> If you use a plain email address it works fine. An example of what
>> causes this problem is as follows:
>>
>> Test
>>
>> The problem is that PHP is formatting the header incorrectly but adding
>> additional < and > tags around the entire address. This is illustrated
>> in this excerpt from my mail server log:
>>
>> 16:28:05.79 5 SMTPI-39353([XXX.XXX.XXX.XXX]) inp: MAIL FROM:
>> >
>>
>> With a plain email address, it still adds the < and > tags, but it
>> works. Here is an example of that from the mail server log:
>>
>> 16:28:21.72 5 SMTPI-39408([XXX.XXX.XXX.XXX]) inp: MAIL
>> FROM:
>
> It seems like a bug.
>
> If you are stuck, you may want to try this package that comes with a
> mail() replacement function written in pure PHP named smtp_mail(). It
> works like mail but it overcomes certain limitations. Take a look at the
> test_smtp_mail.php example script.
>
> http://www.phpclasses.org/mimemessage
>
> You also need this for the delivery:
>
> http://www.phpclasses.org/smtpclass
>
>
> --
>
> Regards,
> Manuel Lemos
>
> PHP professionals looking for PHP jobs
> http://www.phpclasses.org/professionals/
>
> PHP Classes - Free ready to use OOP components written in PHP
> http://www.phpclasses.org/
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
RE: mail() Incorrect Address Format when using IIS7/FastCGI
am 29.01.2008 19:26:03 von Jeff White
------=_NextPart_000_0013_01C8627A.7F5E7C90
Content-Type: text/plain;
charset="US-ASCII"
Content-Transfer-Encoding: 7bit
I have had success with IIS/SMTP using the following function that I found
on the PHP website function list (I've only slightly optimized the original
with some constants). Apparently, IIS/SMTP doesn't like the added '<' and
'>' around the "from" address, but it can be coerced into it with this
function. I've tested successfully with Outlook and Thunderbird.
JW
function send_mail($to, $body, $subject, $fromaddress, $fromname,
$attachments = FALSE)
{
define('EOL', "\r\n");
define('LT', '<');
define('GT', '>');
$headers = '';
$mime_boundary = md5(time());
# Common Headers
$headers .= "From: " . $fromname . LT . $fromaddress .
GT . EOL;
$headers .= "Reply-To: " . $fromname . LT . $fromaddress .
GT . EOL;
$headers .= "Return-Path: " . $fromname . LT . $fromaddress .
GT . EOL;
$headers .= "Message-ID: <" . time() . "-" . $fromaddress .
GT . EOL;
$headers .= "X-Mailer: PHP v" . phpversion() . EOL;
# Boundary for marking the split & Multitype Headers
$headers .= 'MIME-Version: 1.0' . EOL . EOL;
$headers .= "Content-Type: multipart/mixed; boundary=\" ".
$mime_boundary . "\"" . EOL . EOL;
# Open the first part of the mail
$msg = "--" . $mime_boundary . EOL;
$htmlalt_mime_boundary = $mime_boundary . "_htmlalt"; //we must
define a different MIME boundary for this section
# Setup for text OR html -
$msg .= "Content-Type: multipart/alternative; boundary=\"" .
$htmlalt_mime_boundary . "\"" . EOL . EOL;
# Text Version
$msg .= "--" . $htmlalt_mime_boundary . EOL;
$msg .= "Content-Type: text/plain; charset=iso-8859-1" . EOL;
$msg .= "Content-Transfer-Encoding: 8bit" . EOL . EOL;
$msg .= strip_tags(str_replace("
", "\n", substr($body,
(strpos($body, "
") + 6)))) . EOL . EOL;
# HTML Version
$msg .= "--" . $htmlalt_mime_boundary . EOL;
$msg .= "Content-Type: text/html; charset=iso-8859-1" . EOL;
$msg .= "Content-Transfer-Encoding: 8bit" . EOL . EOL;
$msg .= $body . EOL . EOL;
//close the html/plain text alternate portion
$msg .= "--" . $htmlalt_mime_boundary . "--" . EOL . EOL;
if ($attachments !== FALSE)
{
for($i = 0; $i < count($attachments); $i++)
{
if (is_file($attachments[$i]["file"]))
{
# File for Attachment
$file_name = substr($attachments[$i]["file"],
(strrpos($attachments[$i]["file"], "/") + 1));
$handle = fopen($attachments[$i]["file"], 'rb');
$f_contents = fread($handle,
filesize($attachments[$i]["file"]));
$f_contents = chunk_split(base64_encode($f_contents));
//Encode The Data For Transition using base64_encode();
$f_type = filetype($attachments[$i]["file"]);
fclose($handle);
# Attachment
$msg .= "--" . $mime_boundary . EOL;
$msg .= "Content-Type: " . $attachments[$i]["content_type"] .
"; name=\"" . $file_name . "\"" . EOL; // sometimes i have to send MS Word,
use 'msword' instead of 'pdf'
$msg .= "Content-Transfer-Encoding: base64" . EOL;
$msg .= "Content-Description: " . $file_name . EOL;
$msg .= "Content-Disposition: attachment; filename=\"" .
$file_name . "\"" . EOL . EOL; // !! This line needs TWO end of lines !!
IMPORTANT !!
$msg .= $f_contents . EOL . EOL;
}
}
}
# Finished
$msg .= "--" . $mime_boundary . "--" . EOL . EOL; // finish with
two eol's for better security. see Injection.
# SEND THE EMAIL
ini_set(sendmail_from, $fromaddress); // the INI lines are to force
the From Address to be used !
$mail_sent = mail($to, $subject, $msg, $headers);
ini_restore(sendmail_from);
return $mail_sent;
}
?>
-----Original Message-----
From: Dan Richfield [mailto:drichfield@easycgi.com]
Sent: Tuesday, January 29, 2008 11:58
To: php-windows@lists.php.net
Subject: [PHP-WIN] mail() Incorrect Address Format when using IIS7/FastCGI
When using IIS7 with PHP 5.2.5 with the FastCGIModule, the mail()
function returns the following error message when trying to use anything
but a plain email address (ex. test@test.com) in the From or To
headers:
PHP Warning: mail() [function.mail]: SMTP server response: 501 Incorrect
Address Format
If you use a plain email address it works fine. An example of what
causes this problem is as follows:
Test
The problem is that PHP is formatting the header incorrectly but adding
additional < and > tags around the entire address. This is illustrated
in this excerpt from my mail server log:
16:28:05.79 5 SMTPI-39353([XXX.XXX.XXX.XXX]) inp: MAIL FROM:
>
With a plain email address, it still adds the < and > tags, but it
works. Here is an example of that from the mail server log:
16:28:21.72 5 SMTPI-39408([XXX.XXX.XXX.XXX]) inp: MAIL
FROM:
Also, this same behavior was reported in Bug #28038 but I have confirmed
that this is error does not occurs when using this same PHP version in
CGI mode with IIS7. That tells me this bug was fixed, but has reoccured
in 5.2.5 with FastCGI.
Reproduce code:
---------------
$To = "dan@easycgi.com";
$Subject = "Test";
$Body = "Test";
$Headers = "From: Test User " . "\r\n";
mail($To, $Subject, $Body, $Headers);
print "mail sent!";
?>
Expected result:
----------------
True result
Actual result:
--------------
PHP Warning: mail() [function.mail]: SMTP server response: 501 Incorrect
Address Format
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
------=_NextPart_000_0013_01C8627A.7F5E7C90--
Re: mail() Incorrect Address Format when using IIS7/FastCGI
am 29.01.2008 20:35:34 von Manuel Lemos
Hello,
on 01/29/2008 04:13 PM Dan Richfield said the following:
> I have already posted it to bugs.php.net
> (http://bugs.php.net/bug.php?id=43730) and php is claiming it's not a bug.
I am not surprised! ;-(
> Thanks for your suggestion, but I have to use mail because this is being
> offered to shared hosting customers and a mass scale. Most applications
> and developers use the mail() function.
But if mail() does not work and the PHP developers do not want to fix,
it seems you will not solve your problem with the mail() function.
>> It seems like a bug.
>>
>> If you are stuck, you may want to try this package that comes with a
>> mail() replacement function written in pure PHP named smtp_mail(). It
>> works like mail but it overcomes certain limitations. Take a look at the
>> test_smtp_mail.php example script.
>>
>> http://www.phpclasses.org/mimemessage
>>
>> You also need this for the delivery:
>>
>> http://www.phpclasses.org/smtpclass
--
Regards,
Manuel Lemos
PHP professionals looking for PHP jobs
http://www.phpclasses.org/professionals/
PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re: mail() Incorrect Address Format when using IIS7/FastCGI
am 30.01.2008 01:35:00 von Niel Archer
> I have already posted it to bugs.php.net
> (http://bugs.php.net/bug.php?id=43730) and php is claiming it's not a bug.
They are correct, it's not a bug in PHP.
This is the standard behaviour for the Windows implementation of mail() as
noted in the documentation for the function.
Granted it's annoying behaviour, for this reason I use the PEAR Mail
package
--
Niel Archer
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php