Source code for file /phpmailer/phpmailer.php
Documentation is available at phpmailer.php
////////////////////////////////////////////////////
// PHPMailer - PHP email class
// Class for sending email using either
// sendmail, PHP mail(), or SMTP. Methods are
// based upon the standard AspEmail(tm) classes.
// Copyright (C) 2001 - 2003 Brent R. Matzelle
// License: LGPL, see LICENSE
////////////////////////////////////////////////////
* PHPMailer - PHP email transport class
* @author Brent R. Matzelle
* @copyright 2001 - 2003 Brent R. Matzelle
/////////////////////////////////////////////////
/////////////////////////////////////////////////
* Email priority (1 = High, 3 = Normal, 5 = low).
* Sets the CharSet of the message.
* Sets the Content-type of the message.
* Sets the Encoding of the message. Options for this are "8bit",
* "7bit", "binary", "base64", and "quoted-printable".
* Holds the most recent mailer error message.
* Sets the From email address for the message.
var $From =
"root@localhost";
* Sets the From name of the message.
* Sets the Sender email (Return-Path) of the message. If not empty,
* will be sent via -f to sendmail or as 'MAIL FROM' in smtp mode.
* Sets the Subject of the message.
* Sets the Body of the message. This can be either an HTML or text body.
* If HTML then run IsHTML(true).
* Sets the text-only body of the message. This automatically sets the
* email to multipart/alternative. This body can be read by mail
* clients that do not have HTML email capability such as mutt. Clients
* that can read HTML will view the normal Body.
* Sets word wrapping on the body of the message to a given number of
* Method to send mail: ("mail", "sendmail", or "smtp").
* Sets the path of the sendmail program.
* Path to PHPMailer plugins. This is now only useful if the SMTP class
* is in a different directory than the PHP include path.
* Holds PHPMailer version.
* Sets the email address that a reading confirmation will be sent.
* Sets the hostname to use in Message-Id and Received headers
* and as default HELO string. If empty, the value returned
* by SERVER_NAME is used or 'localhost.localdomain'.
/////////////////////////////////////////////////
/////////////////////////////////////////////////
* Sets the SMTP hosts. All hosts must be separated by a
* semicolon. You can also specify a different port
* for each host by using this format: [hostname:port]
* (e.g. "smtp1.example.com:25;smtp2.example.com").
* Hosts will be tried in order.
* Sets the default SMTP server port.
* Sets the SMTP HELO of the message (Default is $Hostname).
* Sets SMTP authentication. Utilizes the Username and Password variables.
* Sets the SMTP server timeout in seconds. This function will not
* work with the win32 version.
* Sets SMTP class debugging on or off.
* Prevents the SMTP connection from being closed after each mail
* sending. If this is set to true then to close the connection
* requires an explicit call to SmtpClose().
var $attachment =
array();
var $CustomHeader =
array();
/////////////////////////////////////////////////
/////////////////////////////////////////////////
* Sets message type to HTML.
* Sets Mailer to send message using SMTP.
* Sets Mailer to send message using PHP mail() function.
* Sets Mailer to send message using the $Sendmail program.
* Sets Mailer to send message using the qmail MTA.
$this->Sendmail =
"/var/qmail/bin/sendmail";
/////////////////////////////////////////////////
/////////////////////////////////////////////////
$this->to[$cur][0] =
trim($address);
$this->to[$cur][1] =
$name;
* Adds a "Cc" address. Note: this function works
* with the SMTP mailer on win32, not with the "mail"
function AddCC($address, $name =
"") {
$this->cc[$cur][0] =
trim($address);
$this->cc[$cur][1] =
$name;
* Adds a "Bcc" address. Note: this function works
* with the SMTP mailer on win32, not with the "mail"
function AddBCC($address, $name =
"") {
$cur =
count($this->bcc);
$this->bcc[$cur][0] =
trim($address);
$this->bcc[$cur][1] =
$name;
* Adds a "Reply-to" address.
$cur =
count($this->ReplyTo);
$this->ReplyTo[$cur][0] =
trim($address);
$this->ReplyTo[$cur][1] =
$name;
/////////////////////////////////////////////////
/////////////////////////////////////////////////
* 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.
$this->SetError($this->Lang("provide_address"));
// Set whether the message is multipart/alternative
$this->error_count =
0; // reset errors
$header .=
$this->CreateHeader();
$body =
$this->CreateBody();
if($body ==
"") { return false; }
$result =
$this->SendmailSend($header, $body);
$result =
$this->MailSend($header, $body);
$result =
$this->SmtpSend($header, $body);
$this->SetError($this->Mailer .
$this->Lang("mailer_not_supported"));
* Sends mail using the $Sendmail program.
function SendmailSend($header, $body) {
if(!@$mail =
popen($sendmail, "w"))
$this->SetError($this->Lang("execute") .
$this->Sendmail);
$result =
pclose($mail) >>
8 & 0xFF;
$this->SetError($this->Lang("execute") .
$this->Sendmail);
* Sends mail using the PHP mail() function.
function MailSend($header, $body) {
for($i =
0; $i <
count($this->to); $i++
)
if($i !=
0) { $to .=
", "; }
$old_from =
ini_get("sendmail_from");
$rt =
@mail($to, $this->EncodeHeader($this->Subject), $body,
$rt =
@mail($to, $this->EncodeHeader($this->Subject), $body, $header);
ini_set("sendmail_from", $old_from);
$this->SetError($this->Lang("instantiate"));
* Sends mail via SMTP using PhpSMTP (Author:
* Chris Ryan). Returns bool. Returns false if there is a
* bad MAIL FROM, RCPT, or DATA input.
function SmtpSend($header, $body) {
if(!$this->SmtpConnect())
if(!$this->smtp->Mail($smtp_from))
$error =
$this->Lang("from_failed") .
$smtp_from;
// Attempt to send attach all recipients
for($i =
0; $i <
count($this->to); $i++
)
if(!$this->smtp->Recipient($this->to[$i][0]))
$bad_rcpt[] =
$this->to[$i][0];
for($i =
0; $i <
count($this->cc); $i++
)
if(!$this->smtp->Recipient($this->cc[$i][0]))
$bad_rcpt[] =
$this->cc[$i][0];
for($i =
0; $i <
count($this->bcc); $i++
)
if(!$this->smtp->Recipient($this->bcc[$i][0]))
$bad_rcpt[] =
$this->bcc[$i][0];
if(count($bad_rcpt) >
0) // Create error message
for($i =
0; $i <
count($bad_rcpt); $i++
)
if($i !=
0) { $error .=
", "; }
$error =
$this->Lang("recipients_failed") .
$error;
if(!$this->smtp->Data($header .
$body))
$this->SetError($this->Lang("data_not_accepted"));