Skip to content

Commit

Permalink
Merged revisions 200-204 via svnmerge from
Browse files Browse the repository at this point in the history
https://phpmailer.svn.sourceforge.net/svnroot/phpmailer/phpmailer/trunk

........
  r200 | coolbru | 2008-11-20 17:20:37 -0500 (Thu, 20 Nov 2008) | 2 lines
  
  Add SMTP error output in error messages, add new language string, as per sf patch: https://sourceforge.net/tracker2/?func=detail&aid=1800644&group_id=26031&atid=385709
........
  r201 | coolbru | 2008-11-20 17:21:44 -0500 (Thu, 20 Nov 2008) | 2 lines
  
  Add test to check for missing translations (will often spot corrupt ones too)
........
  r202 | coolbru | 2008-11-20 17:27:58 -0500 (Thu, 20 Nov 2008) | 7 lines
  
  Add smtp error string to all languages
  Remove stray comment chars in Arabic translation
  Correct UTF-8 encoding of Russian and Chinese translations
  Use single quotes in all array indices in language files
  Remove unnecessary string concatenations and blank lines
  Japanese and Polish are still broken
........
  r203 | coolbru | 2008-11-20 17:43:07 -0500 (Thu, 20 Nov 2008) | 3 lines
  
  Convert getFile function to simpler PHP5 version
  Add a unit test for getFile
........
  r204 | coolbru | 2008-11-21 09:21:06 -0500 (Fri, 21 Nov 2008) | 11 lines
  
  Make address clearing functions also remove entries from all_recipients array
  Add doctype and charset to test output
  Fix error test
  Make test resuts a bit prettier
  Improve addressing tests
  Fix Russian and Polish corrupted language files, make sure all use UTF-8
  Remove BOM from chinese language file
  Make sure file descriptior is closed in EncodeFile
  Fix private access problems to SMTP error message by adding getError function (caused by recent addition of SMTP error reporting)
  All unit tests now pass
........
  • Loading branch information
Carl Corliss committed Dec 1, 2008
1 parent 76a3eb7 commit 2a41627
Show file tree
Hide file tree
Showing 30 changed files with 480 additions and 432 deletions.
135 changes: 72 additions & 63 deletions class.phpmailer.php
Expand Up @@ -539,29 +539,28 @@ public function MailSend($header, $body) {
* @return Bool
* Carl Corliss <rabbitt at users.sourceforge.net>
*/
function SmtpSend_AddRecipients($recipients, &$bad_recipients = array(), &$was_throttled = false, &$throttle_total = -1) {

$total_recipients = count($recipients);
$return_value = true;

for ($i = 0; $i < $total_recipients; $i++) {
if (!$this->smtp->Recipient($recipients[$i])) {
$error = $this->smtp->getLastError();
if (isset($error['smtp_code']) &&
function SmtpSend_AddRecipients($recipients, &$bad_recipients = array(), &$was_throttled = false, &$throttle_total = -1) {
$total_recipients = count($recipients);
$return_value = true;

for ($i = 0; $i < $total_recipients; $i++) {
if (!$this->smtp->Recipient($recipients[$i])) {
$error = $this->smtp->getLastError();
if (isset($error['smtp_code']) &&
($error['smtp_code'] == 451 || $error['smtp_code'] == 452)) {
$was_throttled = true;
$throttle_total = ($i - 1);
$throttle_total = $i;
$return_value = false;
break;
} else {
$bad_recipients[] = $recipients[$i];
$return_value = false;
}
}
}
return $return_value;
}
} else {
$bad_recipients[] = $recipients[$i];
$return_value = false;
}
}
}
return $return_value;
}

/**
* Sends mail via SMTP using PhpSMTP
* Returns false if there is a bad MAIL FROM, RCPT, or DATA input.
Expand Down Expand Up @@ -608,58 +607,58 @@ public function SmtpSend($header, $body) {
$this->SetError($this->Lang('from_failed') . $smtp_from);
$this->smtp->Reset();
return false;
}
}

if (!$this->SmtpSend_AddRecipients($bucket, $bad_rcpt, $was_throttled)) {
if (!$was_throttled && !count($bad_rcpt)) {
$this->SetError($this->Lang('recipients_failed') . join(', ', $bucket));
$this->smtp->Reset();
return false;
}
}
}
}

if (count($bad_rcpt) > 0) { // Create error message
$this->SetError('Error Unknown: ' . $this->Lang('recipients_failed') . join(', ', $bad_rcpt));
$this->smtp->Reset();
return false;
}
}

if (!$this->smtp->Data($header . $body)) {
$this->SetError($this->Lang('data_not_accepted'));
$this->smtp->Reset();
return false;
}
}

$this->smtp->Reset();
}
}

if ($this->SMTPKeepAlive == true) {
$this->smtp->Reset();
} else {
$this->SmtpClose();
}

} else { // No problems adding recipients - proceed normally
if (count($bad_rcpt) > 0) { // Create error message
$this->SetError('Unknown Error: ' . $this->Lang('recipients_failed') . join(', ', $bad_rcpt));
$this->smtp->Reset();
return false;
}
$this->smtp->Reset();
return false;
}

if (!$this->smtp->Data($header . $body)) {
$this->SetError($this->Lang('data_not_accepted'));
$this->smtp->Reset();
return false;
}
$this->SetError($this->Lang('data_not_accepted'));
$this->smtp->Reset();
return false;
}

if ($this->SMTPKeepAlive == true) {
$this->smtp->Reset();
} else {
$this->SmtpClose();
$this->smtp->Reset();
} else {
$this->SmtpClose();
}
}

return true;
}
}

/**
* Initiates a connection to an SMTP server.
Expand Down Expand Up @@ -752,19 +751,20 @@ public function SmtpClose() {
function SetLanguage($lang_type = 'en', $lang_path = 'language/') {
if( !(@include $lang_path.'phpmailer.lang-'.$lang_type.'.php') ) {
$PHPMAILER_LANG = array();
$PHPMAILER_LANG["provide_address"] = 'You must provide at least one ' .
$PHPMAILER_LANG["mailer_not_supported"] = ' mailer is not supported.';
$PHPMAILER_LANG["execute"] = 'Could not execute: ';
$PHPMAILER_LANG["instantiate"] = 'Could not instantiate mail function.';
$PHPMAILER_LANG["authenticate"] = 'SMTP Error: Could not authenticate.';
$PHPMAILER_LANG["from_failed"] = 'The following From address failed: ';
$PHPMAILER_LANG["recipients_failed"] = 'SMTP Error: The following ' .
$PHPMAILER_LANG["data_not_accepted"] = 'SMTP Error: Data not accepted.';
$PHPMAILER_LANG["connect_host"] = 'SMTP Error: Could not connect to SMTP host.';
$PHPMAILER_LANG["file_access"] = 'Could not access file: ';
$PHPMAILER_LANG["file_open"] = 'File Error: Could not open file: ';
$PHPMAILER_LANG["encoding"] = 'Unknown encoding: ';
$PHPMAILER_LANG["signing"] = 'Signing Error: ';
$PHPMAILER_LANG['provide_address'] = 'You must provide at least one recipient email address.';
$PHPMAILER_LANG['mailer_not_supported'] = ' mailer is not supported.';
$PHPMAILER_LANG['execute'] = 'Could not execute: ';
$PHPMAILER_LANG['instantiate'] = 'Could not instantiate mail function.';
$PHPMAILER_LANG['authenticate'] = 'SMTP Error: Could not authenticate.';
$PHPMAILER_LANG['from_failed'] = 'The following From address failed: ';
$PHPMAILER_LANG['recipients_failed'] = 'SMTP Error: The following ' .
$PHPMAILER_LANG['data_not_accepted'] = 'SMTP Error: Data not accepted.';
$PHPMAILER_LANG['connect_host'] = 'SMTP Error: Could not connect to SMTP host.';
$PHPMAILER_LANG['file_access'] = 'Could not access file: ';
$PHPMAILER_LANG['file_open'] = 'File Error: Could not open file: ';
$PHPMAILER_LANG['encoding'] = 'Unknown encoding: ';
$PHPMAILER_LANG['signing'] = 'Signing Error: ';
$PHPMAILER_LANG['smtp_error'] = 'SMTP server error: ';
}
$this->language = $PHPMAILER_LANG;
return true;
Expand Down Expand Up @@ -1324,20 +1324,20 @@ public function AttachAll() {
public function EncodeFile ($path, $encoding = 'base64') {
if(!@$fd = fopen($path, 'rb')) {
$this->SetError($this->Lang('file_open') . $path);
fclose($fd);
return '';
}
if (function_exists('get_magic_quotes')) {
function get_magic_quotes() {
return false;
}
}
}
if (PHP_VERSION < 6) {
$magic_quotes = get_magic_quotes_runtime();
set_magic_quotes_runtime(0);
}
$file_buffer = file_get_contents($path);
$file_buffer = $this->EncodeString($file_buffer, $encoding);
fclose($fd);
if (PHP_VERSION < 6) { set_magic_quotes_runtime($magic_quotes); }
return $file_buffer;
}
Expand Down Expand Up @@ -1686,6 +1686,9 @@ public function InlineImageExists() {
* @return void
*/
public function ClearAddresses() {
foreach($this->to as $to) {
unset($this->all_recipients[strtolower($to[0])]);
}
$this->to = array();
}

Expand All @@ -1694,6 +1697,9 @@ public function ClearAddresses() {
* @return void
*/
public function ClearCCs() {
foreach($this->cc as $cc) {
unset($this->all_recipients[strtolower($cc[0])]);
}
$this->cc = array();
}

Expand All @@ -1702,6 +1708,9 @@ public function ClearCCs() {
* @return void
*/
public function ClearBCCs() {
foreach($this->bcc as $bcc) {
unset($this->all_recipients[strtolower($bcc[0])]);
}
$this->bcc = array();
}

Expand All @@ -1722,6 +1731,7 @@ public function ClearAllRecipients() {
$this->to = array();
$this->cc = array();
$this->bcc = array();
$this->all_recipients = array();
}

/**
Expand All @@ -1747,12 +1757,19 @@ public function ClearCustomHeaders() {

/**
* Adds the error message to the error container.
* Also gets SMTP error if there is one
* Returns void.
* @access private
* @return void
*/
private function SetError($msg) {
$this->error_count++;
if ($this->Mailer == 'smtp' and !is_null($this->smtp)) {
$lasterror = $this->smtp->getError();
if (!empty($lasterror) and array_key_exists('smtp_msg', $lasterror)) {
$msg .= '<p>' . $this->Lang('smtp_error') . $lasterror['smtp_msg'] . "</p>\n";
}
}
$this->ErrorInfo = $msg;
}

Expand Down Expand Up @@ -1995,18 +2012,10 @@ public function set ( $name, $value = '' ) {
*
* @access public
* @param string $filename Parameter File Name
* @return string (or boolean false if it fails to read for any reason)
*/
public function getFile($filename) {
$return = '';
if ($fp = fopen($filename, 'rb')) {
while (!feof($fp)) {
$return .= fread($fp, 1024);
}
fclose($fp);
return $return;
} else {
return false;
}
return @file_get_contents($filename);
}

/**
Expand Down Expand Up @@ -2036,4 +2045,4 @@ public function Sign($cert_filename, $key_filename, $key_pass) {
}
}

?>
?>
13 changes: 11 additions & 2 deletions class.smtp.php
Expand Up @@ -61,7 +61,7 @@ class SMTP {
* Sets whether debugging is turned on
* @var bool
*/
public $do_debug; // the level of debug to perform
public $do_debug = false; // the level of debug to perform

/**
* Sets VERP use on/off (default is off)
Expand Down Expand Up @@ -1109,6 +1109,15 @@ public function client_send($data) {
return fputs($this->smtp_conn, $data);
}

/**
* Get the current error
* @access public
* @return array
*/
public function getError() {
return $this->error;
}

/*******************************************************************
* INTERNAL FUNCTIONS *
******************************************************************/
Expand Down Expand Up @@ -1144,4 +1153,4 @@ private function get_lines() {

}

?>
?>
13 changes: 9 additions & 4 deletions examples/test1.php
Expand Up @@ -3,27 +3,32 @@
include_once('../class.phpmailer.php');

$mail = new PHPMailer();
$mail->isSMTP();

// $mail->SMTPDebug = true;

$body = $mail->getFile('contents.html');

$body = eregi_replace("[\]",'',$body);
$subject = eregi_replace("[\]",'',$subject);

$mail->From = "name@yourdomain.com";
$mail->FromName = "First Last";
$mail->From = "rabbitt@tranquillo.net";
$mail->FromName = "Carl P. Corliss";

$mail->Subject = "PHPMailer Test Subject";

$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test

$mail->MsgHTML($body);

$mail->AddAddress("whoto@otherdomain.com", "John Doe");
for ($i = 1; $i <= 50; $i++) {
$mail->AddAddress("rabbitt+test-$i@gmail.com", "Carl P. Corliss (test #$i)");
$mail->AddCC("rabbitt+test-".($i+50)."@tranquillo.net", "Carl P. Corliss (test #".($i+50).")");
}

if(!$mail->Send()) {
echo 'Failed to send mail';
} else {
echo 'Mail sent';
}

?>
29 changes: 15 additions & 14 deletions language/phpmailer.lang-ar.php
Expand Up @@ -2,24 +2,25 @@
/**
* PHPMailer language file.
* Arabic Version, UTF-8
* by : bahjat al mostafa <bahjat983@hotmail.com> */
* by : bahjat al mostafa <bahjat983@hotmail.com>
*/

$PHPMAILER_LANG = array();

$PHPMAILER_LANG["provide_address"] = 'You must provide at least one ' .
$PHPMAILER_LANG['provide_address'] = 'You must provide at least one ' .
'recipient email address.';
$PHPMAILER_LANG["mailer_not_supported"] = ' mailer غير مدعوم.';
$PHPMAILER_LANG["execute"] = 'لم أستطع تنفيذ : ';
$PHPMAILER_LANG["instantiate"] = 'لم نستطع توفير خدمة البريد.';
$PHPMAILER_LANG["authenticate"] = 'SMTP Error: لم نستطع تأكيد الهوية.';
$PHPMAILER_LANG["from_failed"] = 'البريد التالي لم نستطع ارسال البريد له : ';
$PHPMAILER_LANG["recipients_failed"] = 'SMTP Error: الأخطاء التالية ' .
$PHPMAILER_LANG['mailer_not_supported'] = ' mailer غير مدعوم.';
$PHPMAILER_LANG['execute'] = 'لم أستطع تنفيذ : ';
$PHPMAILER_LANG['instantiate'] = 'لم نستطع توفير خدمة البريد.';
$PHPMAILER_LANG['authenticate'] = 'SMTP Error: لم نستطع تأكيد الهوية.';
$PHPMAILER_LANG['from_failed'] = 'البريد التالي لم نستطع ارسال البريد له : ';
$PHPMAILER_LANG['recipients_failed'] = 'SMTP Error: الأخطاء التالية ' .
'فشل في الارسال لكل من : ';
$PHPMAILER_LANG["data_not_accepted"] = 'SMTP Error: لم يتم قبول المعلومات .';
$PHPMAILER_LANG["connect_host"] = 'SMTP Error: لم نستطع الاتصال بمخدم SMTP.';
$PHPMAILER_LANG["file_access"] = 'لم نستطع الوصول للملف: ';
$PHPMAILER_LANG["file_open"] = 'File Error: لم نستطع فتح الملف: ';
$PHPMAILER_LANG["encoding"] = 'ترميز غير معروف: ';
$PHPMAILER_LANG["signing"] = 'خطأ في التوقيع: ';
$PHPMAILER_LANG['data_not_accepted'] = 'SMTP Error: لم يتم قبول المعلومات .';
$PHPMAILER_LANG['connect_host'] = 'SMTP Error: لم نستطع الاتصال بمخدم SMTP.';
$PHPMAILER_LANG['file_access'] = 'لم نستطع الوصول للملف: ';
$PHPMAILER_LANG['file_open'] = 'File Error: لم نستطع فتح الملف: ';
$PHPMAILER_LANG['encoding'] = 'ترميز غير معروف: ';
$PHPMAILER_LANG['signing'] = 'خطأ في التوقيع: ';
$PHPMAILER_LANG['smtp_error'] = 'SMTP server error: ';
?>

0 comments on commit 2a41627

Please sign in to comment.