From 7590cdf2468dcdbd9b4af964747dcb542f7ac3c9 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sun, 29 Jan 2006 17:29:48 +0000 Subject: [PATCH] Multi-address send should now work --- mail.php | 67 ++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 46 insertions(+), 21 deletions(-) diff --git a/mail.php b/mail.php index bf0281c..584114c 100644 --- a/mail.php +++ b/mail.php @@ -231,17 +231,43 @@ class Mail */ function send() { + // check the required stuff $this->registry->check_isso_fields(get_class($this)); + if (sizeof($this->to) < 1) + { + trigger_error('You need at least one email address to send to', E_USER_ERROR); + return false; + } + // make sure we have a mailer + // #*# add support for SMTP if (!@ini_get('sendmail_path')) { $this->registry->debug("email: no sendmail -> not sending"); return false; } - $this->to = $this->_fetch_first_line($this->to); - $this->from = $this->_fetch_first_line($this->from); + // sort out the to addresses + $tolist = array(); + foreach ($this->to AS $address => $name) + { + $address = $this->_fetch_first_line($address); + $address = trim($this->registry->unsanitize($address)); + $name = $this->_fetch_first_line($name); + $name = trim($this->registry->unsanitize($name)); + + if ($name == null) + { + $tolist[] = $address; + } + else + { + $tolist[] = "\"$name\" <$address>"; + } + } + // sanitize the from field + $this->from = $this->_fetch_first_line($this->from); if (!$this->from) { $this->registry->debug("email: no from -> not sending"); @@ -252,6 +278,7 @@ class Mail $this->from = trim($this->registry->unsanitize($this->from)); } + // sanitize the from name if (!$this->fromname) { $this->fromname = $this->from; @@ -261,16 +288,7 @@ class Mail $this->fromname = trim($this->registry->unsanitize($this->fromname)); } - if (!$this->to) - { - $this->registry->debug("email: no recipient -> not sending"); - return false; - } - else - { - $this->to = trim($this->registry->unsanitize($this->to)); - } - + // sanitize the subject if (!$this->subject) { $this->registry->debug("email: no subject -> not sending"); @@ -280,7 +298,7 @@ class Mail { $this->subject = trim($this->registry->unsanitize($this->_fetch_first_line($this->subject))); } - + // sanitize the body if (!$this->body) { $this->registry->debug("email: no body -> not sending"); @@ -292,6 +310,7 @@ class Mail $this->body = trim($this->registry->unsanitize($this->body, true)); } + // attach additional headers $this->headers = $this->registry->modules['functions']->convert_line_breaks($this->headers); $this->headers .= "From: \"{$this->fromname}\" <{$this->from}>\n"; $this->headers .= "Return-Path: {$this->from}\n"; @@ -299,15 +318,21 @@ class Mail $this->headers .= "Content-Type: text/plain; charset=\"iso-8859-1\"\n"; $this->headers .= "Content-Transfer-Encoding: 7bit\n"; - if (mail($this->to, $this->subject, $this->body, trim($this->headers), "-f {$this->from}")) - { - $this->registry->debug("email: sent -> good"); - return true; - } - else + $this->headers = trim($this->headers); + + // attempt to send the mail! + foreach ($tolist AS $address) { - $this->registry->debug("email: sent -> error"); - return false; + if (mail($address, $this->subject, $this->body, $this->headers, "-f {$this->from}")) + { + $this->registry->debug("email: sent -> good"); + return true; + } + else + { + $this->registry->debug("email: sent -> error"); + return false; + } } } -- 2.43.5