From bd9778067c4a478f247956f9ccd51731097fdfdc Mon Sep 17 00:00:00 2001 From: Sean Harvey Date: Wed, 25 Mar 2009 21:43:01 +0000 Subject: [PATCH] BUGFIX Fixed potential PHP notices if headers array not set for Bcc and Cc git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@73651 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- email/Email.php | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/email/Email.php b/email/Email.php index c5a015f68..2d0d3f736 100755 --- a/email/Email.php +++ b/email/Email.php @@ -399,18 +399,24 @@ class Email extends ViewableData { if($this->bcc) $subject .= ", bcc to $this->bcc"; $subject .= ']'; } else { - if($this->cc) $headers["Cc"] = $this->cc; - if($this->bcc) $headers["Bcc"] = $this->bcc; + if($this->cc) $headers['Cc'] = $this->cc; + if($this->bcc) $headers['Bcc'] = $this->bcc; } if(self::$cc_all_emails_to) { - if(trim($headers['Cc'])) $headers['Cc'] .= ', '; - $headers['Cc'] .= self::$cc_all_emails_to; + if(!empty($headers['Cc']) && trim($headers['Cc'])) { + $headers['Cc'] .= ', ' . self::$cc_all_emails_to; + } else { + $headers['Cc'] = self::$cc_all_emails_to; + } } if(self::$bcc_all_emails_to) { - if(trim($headers['Bcc'])) $headers['Bcc'] .= ', '; - $headers['Bcc'] .= self::$bcc_all_emails_to; + if(!empty($headers['Bcc']) && trim($headers['Bcc'])) { + $headers['Bcc'] .= ', ' . self::$bcc_all_emails_to; + } else { + $headers['Bcc'] = self::$bcc_all_emails_to; + } } Requirements::restore(); @@ -456,8 +462,8 @@ class Email extends ViewableData { unset($headers['Cc']); unset($headers['Bcc']); } else { - if($this->cc) $headers["Cc"] = $this->cc; - if($this->bcc) $headers["Bcc"] = $this->bcc; + if($this->cc) $headers['Cc'] = $this->cc; + if($this->bcc) $headers['Bcc'] = $this->bcc; } if(self::$cc_all_emails_to) { @@ -475,7 +481,7 @@ class Email extends ViewableData { $headers['Bcc'] = self::$bcc_all_emails_to; } } - + Requirements::restore(); return self::mailer()->sendHTML($to, $this->from, $subject, $this->body, $this->attachments, $headers, $this->plaintext_body);