views:

108

answers:

2

Hi!

Zend Mail throws an exception (because mail() returns false) when the to name is set to something with both a foreign character (like "å") and a comma (","). Re-produce with code below.

$mail = new Zend_Mail('utf-8');
$mail
    ->setFrom('info@myhost', 'My company')
    ->setSubject('hi')
    ->addTo('[email protected]', 'aå,a')
    ->setBodyHtml('<p>asd</p>')
    ->send();

If I change the addTo call to something of the below, no error occurs.

->addTo('[email protected]', 'aåa')
->addTo('[email protected]', 'a,a')
->addTo('[email protected]', 'aa')

The weird thing is, even though it throws an exception ("Unable to send mail"), the mail is delivered. I'm running the latest Zend Mail (1.9.5?). Please halp!

A: 

The problem is that mail() function for $to accepts

User <[email protected]>, Another User <[email protected]>

and I guess that PHP internally splits the string on commas to separate multiple recipients but you are providing only one email address.

If you think this is a Zend_Mail, or PHP bug you should post this to the appropriate issue tracker.

Goran Jurić
A: 

The comma is a reserved literal in the "to" part of a mail header (and you should never use it though), separating different targets. Even if your "first" mail gets sent, imho it creates a header like this:

aå, a <[email protected]>

With this header i assume your mta tries to send two mails: one to aå, which fails (badly), and a second one to [email protected], which should make its way. You could try to look into the mail headers to confirm this theory.

Karsten