Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Resolved issue 0000977: Error on sendmail with smtp
git-svn-id: http://piwigo.org/svn/trunk@3261 68402e56-0260-453c-a942-63ccdbb3a9ee
  • Loading branch information
rub committed Apr 26, 2009
1 parent 45f95d6 commit 24ed6da
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions include/class_smtp_mail.inc.php
Expand Up @@ -73,13 +73,27 @@ function server_write($s)
return $this->no_error;
}

function add_recipients(&$recipients, $headers, $type_header)
{
if (preg_match('/^\s*'.$type_header.'\s*:.*/mi', $headers, $matches) != 0)
{
$list = explode(',', $matches[0]);
foreach ($list as $email)
{
if (strpos($email, '<') !== false)
{
$email = preg_replace('/.*<(.*)>.*/i', '$1', $email);
}
$recipients[] = trim($email);
}
}
}

// Adaptation of pun_mail
function mail($to, $subject, $message, $headers = '')
{
$this->no_error = true;

$recipients = explode(',', $to);

// Are we using port 25 or a custom port?
if (strpos($this->host, ':') !== false)
{
Expand Down Expand Up @@ -118,15 +132,27 @@ function mail($to, $subject, $message, $headers = '')
$this->server_write('MAIL FROM:<'.$this->email_webmaster.'>'."\r\n");
$this->server_parse('250');

if (preg_match('/^\s*to\s*:.*/mi', $headers) === 0)
if ((preg_match('/^\s*to\s*:.*/mi', $headers) === 0) and !empty($to))
{
$to_header = 'To:'.implode(',', array_map(create_function('$email','return "<".$email.">";'), $recipients));
$to_header = 'To:'.implode(',', array_map(create_function('$email','return "<".$email.">";'), explode(',', $to)));
}
else
{
$to_header = '';
}

if (!empty($to))
{
$recipients = explode(',', $to);
}
else
{
$recipients = array();
}

$this->add_recipients($recipients, $headers, 'Cc');
$this->add_recipients($recipients, $headers, 'Bcc');

@reset($recipients);
while (list(, $email) = @each($recipients))
{
Expand Down

0 comments on commit 24ed6da

Please sign in to comment.