protected function PHPMailer::SmtpSend in SMTP Authentication Support 7.2
Same name and namespace in other branches
- 5 smtp.module \PHPMailer::SmtpSend()
- 7 smtp.phpmailer.inc \PHPMailer::SmtpSend()
Sends mail via SMTP using PhpSMTP Returns FALSE if there is a bad MAIL FROM, RCPT, or DATA input.
@uses SMTP @access protected
Parameters
string $header The message headers:
string $body The message body:
Return value
bool
1 call to PHPMailer::SmtpSend()
- PHPMailer::Send in ./
smtp.phpmailer.inc - Creates message and assigns Mailer. If the message is not sent successfully then it returns FALSE. Use the ErrorInfo variable to view description of the error.
File
- ./
smtp.phpmailer.inc, line 673 - The mail handler class in smtp module, based on code of the phpmailer library, customized and relicensed to GPLv2.
Class
- PHPMailer
- PHPMailer - PHP email transport class NOTE: Requires PHP version 5 or later @package PHPMailer @author Andy Prevost @author Marcus Bointon @copyright 2004 - 2009 Andy Prevost
Code
protected function SmtpSend($header, $body) {
$bad_rcpt = array();
if (!$this
->SmtpConnect()) {
throw new phpmailerException(t('SMTP Error: Could not connect to SMTP host.'), self::STOP_CRITICAL);
}
$smtp_from = $this->Sender == '' ? $this->From : $this->Sender;
if (!$this->smtp
->Mail($smtp_from)) {
throw new phpmailerException(t('The following From address failed: !from', array(
'!from' => $smtp_from,
)), self::STOP_CRITICAL);
}
// Attempt to send attach all recipients
foreach ($this->to as $to) {
if (!$this->smtp
->Recipient($to[0])) {
$bad_rcpt[] = $to[0];
// implement call back function if it exists
$isSent = 0;
$this
->doCallback($isSent, $to[0], '', '', $this->Subject, $body);
}
else {
// implement call back function if it exists
$isSent = 1;
$this
->doCallback($isSent, $to[0], '', '', $this->Subject, $body);
}
}
foreach ($this->cc as $cc) {
if (!$this->smtp
->Recipient($cc[0])) {
$bad_rcpt[] = $cc[0];
// implement call back function if it exists
$isSent = 0;
$this
->doCallback($isSent, '', $cc[0], '', $this->Subject, $body);
}
else {
// implement call back function if it exists
$isSent = 1;
$this
->doCallback($isSent, '', $cc[0], '', $this->Subject, $body);
}
}
foreach ($this->bcc as $bcc) {
if (!$this->smtp
->Recipient($bcc[0])) {
$bad_rcpt[] = $bcc[0];
// implement call back function if it exists
$isSent = 0;
$this
->doCallback($isSent, '', '', $bcc[0], $this->Subject, $body);
}
else {
// implement call back function if it exists
$isSent = 1;
$this
->doCallback($isSent, '', '', $bcc[0], $this->Subject, $body);
}
}
if (count($bad_rcpt) > 0) {
//Create error message for any bad addresses
$badaddresses = implode(', ', $bad_rcpt);
throw new phpmailerException(t('SMTP Error: The following recipients failed: !bad', array(
'!bad' => $badaddresses,
)));
}
if (!$this->smtp
->Data($header . $body)) {
throw new phpmailerException(t('SMTP Error: Data not accepted.'), self::STOP_CRITICAL);
}
if ($this->SMTPKeepAlive == TRUE) {
$this->smtp
->Reset();
}
return TRUE;
}