php-windows Digest 31 Jan 2008 19:00:52 -0000 Issue 3416

Topics (messages 28761 through 28766):

Re: mail() Incorrect Address Format when using IIS7/FastCGI
        28761 by: Manuel Lemos
        28762 by: Dan Richfield
        28763 by: Jeff White
        28764 by: Manuel Lemos
        28765 by: Niel Archer

Cannot load php_pdo_mysql
        28766 by: Robert Denton

Administrivia:

To subscribe to the digest, e-mail:
        [EMAIL PROTECTED]

To unsubscribe from the digest, e-mail:
        [EMAIL PROTECTED]

To post to the list, e-mail:
        [EMAIL PROTECTED]


----------------------------------------------------------------------
--- Begin Message ---
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. [EMAIL PROTECTED]) 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 <[EMAIL PROTECTED]>
> 
> 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:<Test
> <[EMAIL PROTECTED]>>
> 
> 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:<[EMAIL PROTECTED]>

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/

--- End Message ---
--- Begin Message --- 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" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]
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. [EMAIL PROTECTED]) 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 <[EMAIL PROTECTED]>

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:<Test
<[EMAIL PROTECTED]>>

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:<[EMAIL PROTECTED]>

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/

--- End Message ---
--- Begin Message ---
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

 

<?php

      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("<br>", "\n", substr($body,
(strpos($body, "<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:[EMAIL PROTECTED] 
Sent: Tuesday, January 29, 2008 11:58
To: [EMAIL PROTECTED]
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. [EMAIL PROTECTED]) 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 <[EMAIL PROTECTED]>

 

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:<Test

<[EMAIL PROTECTED]>>

 

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:<[EMAIL PROTECTED]>

 

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:

---------------

<?php

$To = "[EMAIL PROTECTED]";

$Subject = "Test";

$Body = "Test";

$Headers = "From: Test User <[EMAIL PROTECTED]>" . "\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

 


--- End Message ---
--- Begin Message ---
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/

--- End Message ---
--- Begin Message ---
> 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

--- End Message ---
--- Begin Message ---
Hi folks,

After upgrading from php 5.2.? to php 5.2.5  I am now getting two errors I 
never got before when surfing around our wiki.  The first just shows up in the 
error log:

[31-Jan-2008 10:38:48] PHP Warning:  PHP Startup: Unable to load dynamic 
library 'C:\php\ext\php_pdo_mysql.dll' - The specified module could not be 
found.  
 in Unknown on line 0

However, the extensions dir is correctly defined in the php.ini file, as is 
evidenced that it can load other extension from that very same directory.  For 
example, it can load php_mysql.dll just fine.  Oddly, there do not seem to be 
any negative impacts on the users of the wiki (due to this error) although this 
definitely bothers me as an admin.  

Any suggestions as to why this might be occurring?

The second error....  er...  No, I'll put that in a second email.

Robert

--- End Message ---

Reply via email to