/*~ class.phpmailer.php
.---------------------------------------------------------------------------.
| Software: PHPMailer - PHP email class |
-| Version: 5.2 |
+| Version: 5.2.1 |
| Site: https://code.google.com/a/apache-extras.org/p/phpmailer/ |
| ------------------------------------------------------------------------- |
| Admin: Jim Jagielski (project admininistrator) |
| : Marcus Bointon (coolbru) coolbru@users.sourceforge.net |
| : Jim Jagielski (jimjag) jimjag@gmail.com |
| Founder: Brent R. Matzelle (original founder) |
-| Copyright (c) 2010-2011, Jim Jagielski. All Rights Reserved. |
+| Copyright (c) 2010-2012, Jim Jagielski. All Rights Reserved. |
| Copyright (c) 2004-2009, Andy Prevost. All Rights Reserved. |
| Copyright (c) 2001-2003, Brent R. Matzelle |
| ------------------------------------------------------------------------- |
* @author Andy Prevost
* @author Marcus Bointon
* @author Jim Jagielski
- * @copyright 2010 - 2011 Jim Jagielski
+ * @copyright 2010 - 2012 Jim Jagielski
* @copyright 2004 - 2009 Andy Prevost
* @version $Id: class.phpmailer.php 450 2010-06-23 16:46:33Z coolbru $
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
*/
protected $MIMEHeader = '';
+ /**
+ * Stores the complete sent MIME message (Body and Headers)
+ * @var string
+ * @access protected
+ */
+ protected $SentMIMEMessage = '';
+
/**
* Sets word wrapping on the body of the message to a given number of
* characters.
* Sets the PHPMailer Version number
* @var string
*/
- public $Version = '5.2';
+ public $Version = '5.2.1';
/**
* What to use in the X-Mailer header
* @return boolean
*/
public function AddReplyTo($address, $name = '') {
- return $this->AddAnAddress('ReplyTo', $address, $name);
+ return $this->AddAnAddress('Reply-To', $address, $name);
}
/**
* @access protected
*/
protected function AddAnAddress($kind, $address, $name = '') {
- if (!preg_match('/^(to|cc|bcc|ReplyTo)$/', $kind)) {
+ if (!preg_match('/^(to|cc|bcc|Reply-To)$/', $kind)) {
$this->SetError($this->Lang('Invalid recipient array').': '.$kind);
if ($this->exceptions) {
throw new phpmailerException('Invalid recipient array: ' . $kind);
}
- echo $this->Lang('Invalid recipient array').': '.$kind;
+ if ($this->SMTPDebug) {
+ echo $this->Lang('Invalid recipient array').': '.$kind;
+ }
return false;
}
$address = trim($address);
if ($this->exceptions) {
throw new phpmailerException($this->Lang('invalid_address').': '.$address);
}
- echo $this->Lang('invalid_address').': '.$address;
+ if ($this->SMTPDebug) {
+ echo $this->Lang('invalid_address').': '.$address;
+ }
return false;
}
- if ($kind != 'ReplyTo') {
+ if ($kind != 'Reply-To') {
if (!isset($this->all_recipients[strtolower($address)])) {
array_push($this->$kind, array($address, $name));
$this->all_recipients[strtolower($address)] = true;
if ($this->exceptions) {
throw new phpmailerException($this->Lang('invalid_address').': '.$address);
}
- echo $this->Lang('invalid_address').': '.$address;
+ if ($this->SMTPDebug) {
+ echo $this->Lang('invalid_address').': '.$address;
+ }
return false;
}
$this->From = $address;
$this->FromName = $name;
if ($auto) {
if (empty($this->ReplyTo)) {
- $this->AddAnAddress('ReplyTo', $address, $name);
+ $this->AddAnAddress('Reply-To', $address, $name);
}
if (empty($this->Sender)) {
$this->Sender = $address;
if(!$this->PreSend()) return false;
return $this->PostSend();
} catch (phpmailerException $e) {
+ $this->SentMIMEMessage = '';
$this->SetError($e->getMessage());
if ($this->exceptions) {
throw $e;
protected function PreSend() {
try {
+ $mailHeader = "";
if ((count($this->to) + count($this->cc) + count($this->bcc)) < 1) {
throw new phpmailerException($this->Lang('provide_address'), self::STOP_CRITICAL);
}
$this->MIMEHeader = $this->CreateHeader();
$this->MIMEBody = $this->CreateBody();
+ // To capture the complete message when using mail(), create
+ // an extra header list which CreateHeader() doesn't fold in
+ if ($this->Mailer == 'mail') {
+ if (count($this->to) > 0) {
+ $mailHeader .= $this->AddrAppend("To", $this->to);
+ } else {
+ $mailHeader .= $this->HeaderLine("To", "undisclosed-recipients:;");
+ }
+ $mailHeader .= $this->HeaderLine('Subject', $this->EncodeHeader($this->SecureHeader(trim($this->Subject))));
+ // if(count($this->cc) > 0) {
+ // $mailHeader .= $this->AddrAppend("Cc", $this->cc);
+ // }
+ }
// digitally sign with DKIM if enabled
if ($this->DKIM_domain && $this->DKIM_private) {
$this->MIMEHeader = str_replace("\r\n", "\n", $header_dkim) . $this->MIMEHeader;
}
+ $this->SentMIMEMessage = sprintf("%s%s\r\n\r\n%s",$this->MIMEHeader,$mailHeader,$this->MIMEBody);
return true;
+
} catch (phpmailerException $e) {
$this->SetError($e->getMessage());
if ($this->exceptions) {
return $this->SendmailSend($this->MIMEHeader, $this->MIMEBody);
case 'smtp':
return $this->SmtpSend($this->MIMEHeader, $this->MIMEBody);
+ case 'mail':
+ return $this->MailSend($this->MIMEHeader, $this->MIMEBody);
default:
return $this->MailSend($this->MIMEHeader, $this->MIMEBody);
}
if ($this->exceptions) {
throw $e;
}
- echo $e->getMessage()."\n";
+ if ($this->SMTPDebug) {
+ echo $e->getMessage()."\n";
+ }
return false;
}
}
$to = implode(', ', $toArr);
if (empty($this->Sender)) {
- $params = "-oi -f %s";
+ $params = "-oi ";
} else {
$params = sprintf("-oi -f %s", $this->Sender);
}
$this->doCallback($isSent, $val, $this->cc, $this->bcc, $this->Subject, $body);
}
} else {
- $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header);
+ $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
// implement call back function if it exists
$isSent = ($rt == 1) ? 1 : 0;
$this->doCallback($isSent, $to, $this->cc, $this->bcc, $this->Subject, $body);
}
} catch (phpmailerException $e) {
$this->smtp->Reset();
- throw $e;
+ if ($this->exceptions) {
+ throw $e;
+ }
}
return true;
}
$result .= $this->HeaderLine('To', 'undisclosed-recipients:;');
}
}
- }
+ }
$from = array();
$from[0][0] = trim($this->From);
}
if(count($this->ReplyTo) > 0) {
- $result .= $this->AddrAppend('Reply-to', $this->ReplyTo);
+ $result .= $this->AddrAppend('Reply-To', $this->ReplyTo);
}
// mail() sets the subject itself
return $result;
}
+ /**
+ * Returns the MIME message (headers and body). Only really valid post PreSend().
+ * @access public
+ * @return string
+ */
+ public function GetSentMIMEMessage() {
+ return $this->SentMIMEMessage;
+ }
+
+
/**
* Assembles the message body. Returns an empty string on failure.
* @access public
$signed = tempnam("", "signed");
if (@openssl_pkcs7_sign($file, $signed, "file://".$this->sign_cert_file, array("file://".$this->sign_key_file, $this->sign_key_pass), NULL)) {
@unlink($file);
- @unlink($signed);
$body = file_get_contents($signed);
+ @unlink($signed);
} else {
@unlink($file);
@unlink($signed);
if ($this->exceptions) {
throw $e;
}
- echo $e->getMessage()."\n";
+ if ($this->SMTPDebug) {
+ echo $e->getMessage()."\n";
+ }
if ( $e->getCode() == self::STOP_CRITICAL ) {
return false;
}
return false;
}
}
- if (version_compare(PHP_VERSION, '5.3.0', '<')) {
- $magic_quotes = get_magic_quotes_runtime();
- set_magic_quotes_runtime(0);
- }
+ $magic_quotes = get_magic_quotes_runtime();
+ if ($magic_quotes) {
+ if (version_compare(PHP_VERSION, '5.3.0', '<')) {
+ set_magic_quotes_runtime(0);
+ } else {
+ ini_set('magic_quotes_runtime', 0);
+ }
+ }
$file_buffer = file_get_contents($path);
$file_buffer = $this->EncodeString($file_buffer, $encoding);
- if (version_compare(PHP_VERSION, '5.3.0', '<')) {
- set_magic_quotes_runtime($magic_quotes);
- }
+ if ($magic_quotes) {
+ if (version_compare(PHP_VERSION, '5.3.0', '<')) {
+ set_magic_quotes_runtime($magic_quotes);
+ } else {
+ ini_set('magic_quotes_runtime', $magic_quotes);
+ }
+ }
return $file_buffer;
} catch (Exception $e) {
$this->SetError($e->getMessage());
* @return $message
*/
public function MsgHTML($message, $basedir = '') {
- preg_match_all("/(src|background)=\"(.*)\"/Ui", $message, $images);
+ preg_match_all("/(src|background)=[\"'](.*)[\"']/Ui", $message, $images);
if(isset($images[2])) {
foreach($images[2] as $i => $url) {
// do not change urls for absolute images (thanks to corvuscorax)
if ( strlen($basedir) > 1 && substr($basedir, -1) != '/') { $basedir .= '/'; }
if ( strlen($directory) > 1 && substr($directory, -1) != '/') { $directory .= '/'; }
if ( $this->AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64', $mimeType) ) {
- $message = preg_replace("/".$images[1][$i]."=\"".preg_quote($url, '/')."\"/Ui", $images[1][$i]."=\"".$cid."\"", $message);
+ $message = preg_replace("/".$images[1][$i]."=[\"']".preg_quote($url, '/')."[\"']/Ui", $images[1][$i]."=\"".$cid."\"", $message);
}
}
}
}
$this->IsHTML(true);
$this->Body = $message;
- $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s', '', $message)));
- if (!empty($textMsg) && empty($this->AltBody)) {
- $this->AltBody = html_entity_decode($textMsg);
- }
+ if (empty($this->AltBody)) {
+ $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s', '', $message)));
+ if (!empty($textMsg)) {
+ $this->AltBody = html_entity_decode($textMsg, ENT_QUOTES, $this->CharSet);
+ }
+ }
if (empty($this->AltBody)) {
$this->AltBody = 'To view this email message, open it in a program that understands HTML!' . "\n\n";
}
+ return $message;
}
/**