Hey,
I think I’ve stumbled upon a bug with the Email library of CI, latest version 1.7.
I am using Mercury as a localhost SMTP server as part of XAMPP and it throws 501 Bad recipient address syntax errors at me.
I have dug a little deeper and found that CI is sending what appears to be a bad From: header syntax.
The correct syntax for From headers as far as I can make out from the RFC is
From: .(JavaScript must be enabled to view this email address)
From: Code Igniter <joe@bloggs.com>
From: .(JavaScript must be enabled to view this email address), .(JavaScript must be enabled to view this email address)
If I use CI->email->send(“joe@bloggs.com”) then CI sends
From: <joe@bloggs.com>
And CI->email->send(“joe@bloggs.com”, “Code Igniter”) sends
From: “Code Igniter” <joe@bloggs.com>
Both of which are syntactically wrong, or if not wrong they do not match the syntax I have found from the RFC and the mail server I am sending to does not like it either.
If I modify the CI source for the from function to account for the syntax.
function from($from, $name = '')
{
if (preg_match( '/\<(.*)\>/', $from, $match))
{
$from = $match['1'];
}
$return_path = $from;
if ($this->validate)
{
$this->validate_email($this->_str_to_array($from));
}
// prepare the display name
if ($name != '')
{
// only use Q encoding if there are characters that would require it
if ( ! preg_match('/[\200-\377]/', $name))
{
// add slashes for non-printing characters, slashes, and double quotes, and surround it in double quotes
$name = addcslashes($name, "\0..\37\177'\"\\");
}
else
{
$name = $this->_prep_q_encoding($name, TRUE);
}
$from = ' <'.$from.'>';
}
$this->_set_header('From', $name.$from);
$this->_set_header('Return-Path', '<'.$return_path.'>');
}
This produces
[From] => .(JavaScript must be enabled to view this email address)
[Return-Path] => <joe@bloggs.com>
Which works when not using a name in the from() call.
The above function, when using a name to the from() function will produce as per the syntax
[From] => Code Ingiter <joe@bloggs.com>
[Return-Path] => <joe@bloggs.com>
However, this still breaks the mail server and I get the 501 error again despite this matching the correct syntax.
So not too sure about what is happening when using a from name.
Any ideas/suggestions? Am I wrong about the syntax here or is there an issue going on?
Cheers
