PHPMailer - PHP email transport class
Version: ico_20070613
Copyright: 2001 - 2003 Brent R. Matzelle
License: LGPL, see LICENSE
PHP version: 5
Required modules: standard, streams, pcre, hash
Required packages: class.smtp.php
Author: Brent R. Matzelle, Umberto Salsi (porting to PHP5)
Class for sending email using either sendmail, PHP mail(), or SMTP. A message can be either a plain text or an HTML text, possibly with embedded images and attachments.
PHPMailer-ico has been converted from PHP 4 to PHP 5 from the original PHPMailer 1.73 version. This package can be downloaded from www.icosaedro.it/phpmailer.
FIXME: SmtpSend() fails and no email is sent if any of the recipients is not accepted by the server; the program cannot know which one failed or it must send every copy of the message to any recipient, one by one. The interface to the SMTP class should be redesigned to resolve this issue.
BUG: filenames are not encoded as per the RFC 2047 "MIME headers".
class PHPMailer
{
const VERSION = "ico_20070415"Holds PHPMailer-ico version.
const SENDMAIL_PATH = "/usr/sbin/sendmail"
const QMAIL_PATH = "/var/qmail/bin/sendmail"int $Priority = 3Email priority (1 = High, 3 = Normal, 5 = low).
string $CharSet = "iso-8859-1"Sets the CharSet of the message
This sets the charset you will use either for the subject and the body (text and HTML) of the message.
string $Encoding = "8bit"Sets the Encoding of the message.
Options for this are "8bit", "7bit", "binary", "base64", and "quoted-printable".
string $ErrorInfo = ""Holds the most recent mailer error message.
string $From = "root@localhost"Sets the From email address for the message.
Remember to validate the email through ::IsValidEmailAddress().
string $FromName = "Root User"Sets the From name of the message.
string $Sender = ""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. Remember to validate the email through ::IsValidEmailAddress().
string $Subject = ""Sets the subject of the message
The string must be encoded accordingly to the ::$CharSet variable. The "Subject:" header will be encoded properly to render the given charset.
string $Body = ""Sets the Body of the message.
This can be either an HTML or text body. If HTML then run ::IsHTML(TRUE). The charset of this string must be ::$CharSet. See also ::$AltBody if you want to set an alternate plain text version of the message.
string $AltBody = ""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. The charset of this string must be ::$CharSet.
int $WordWrap = 0Sets word wrapping on the body of the message to a given number of characters
Lines longher than that are splitted. 0 = no word wrap.
string $Sendmail = "/usr/sbin/sendmail"The path of the sendmail program
string $ConfirmReadingTo = ""Sets the email address that a reading confirmation will be sent.
Remember to validate the email through ::IsValidEmailAddress().
string $Hostname = ""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'.
string $Host = "localhost"Sets the SMTP hosts
You can list one or several servers separated by semicolon and possibly with a port number separated with a colon, for example: "host1;host2:25;host3:1025". The default TCP port is 25. The listed hosts are tried in order, the first accepting the connection and possibly the authentication login is used.
string $Helo = ""Sets the SMTP HELO of the message (Default is ::$Hostname).
boolean $SMTPAuth = FALSESets SMTP authentication.
Utilizes the ::$Username and ::$Password variables.
string $Username = ""Sets SMTP username.
string $Password = ""Sets SMTP password.
int $Timeout = 10Sets the SMTP server timeout in seconds.
This function will not work with the win32 version.
boolean $SMTPDebug = FALSESets SMTP class debugging on or off.
boolean $SMTPKeepAlive = FALSEPrevents 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().
void IsHTML(boolean $xbool)Sets message type to HTML (TRUE) or plain text (FALSE)
void IsSMTP()Sets Mailer to send message using SMTP protocol
void IsMail()Sets Mailer to send message using PHP mail() function
void IsSendmail()Sets Mailer to send message using ::$Sendmail program
void IsQmail()Sets Mailer to send message using the qmail MTA.
static boolean IsValidEmailAddress(string $email)Return TRUE is $email is a valid email address
Valid email address are specified by RFC 2822. This method implements a sub-set of this syntax that can be described as follows. The address has the form user@domain where the user part and the domain part are made of one or more "atoms" separated by a dot. Every atom is a sequence of one or more letters of the US-ASCII charset, digits or any of the following characters:
! # $ % & ' * + - / = ? ^ _ ` { | } ~void AddAddress(string $address, string $name = "")
throws ErrorExceptionAdds a "To" address.
The $name, if provided, must be encoded using the charset specified by ::$CharSet.
An exception is thrown if the address provided isn't a valid email address according to ::IsValidEmailAddress().
void AddCC(string $address, string $name = "")
throws ErrorExceptionAdds a "Cc" address.
Note: this function works with the SMTP mailer on win32, not with the "mail" mailer.
An exception is thrown if the address provided isn't a valid email address according to ::IsValidEmailAddress().
void AddBCC(string $address, string $name = "")
throws ErrorExceptionAdds a "Bcc" address.
Note: this function works with the SMTP mailer on win32, not with the "mail" mailer. FIXME: verify last sentence.
An exception is thrown if the address provided isn't a valid email address according to ::IsValidEmailAddress().
void AddReplyTo(string $address, string $name = "")
throws ErrorExceptionAdds a "Reply-to" address.
An exception is thrown if the address provided isn't a valid email address according to ::IsValidEmailAddress().
void AddCustomHeader(string $custom_header)Adds a custom header
This method accept only one header, with header name and header body separated by a colon. Several headers can be added calling this method several times. If the header body contains non-ASCII characters, when the email will be sent, it is encoded properly using the given ::$CharSet.
void SetLanguage(string $lang_type, string $lang_path = "language/")Sets the language for all class error messages.
This method simply save internally these parameters; for efficiency, the translation file isn't actually loaded until a first error message is actually raised. The default language type is "en" and the default directory of the translation files is "language/".
boolean IsError()Returns TRUE if an error occurred.
void SmtpClose()
throws ErrorExceptionCloses the active SMTP session if one exists.
boolean SmtpSend(string $header, string $body)
throws Exception, ErrorExceptionSends mail via SMTP using PhpSMTP.
Author: Chris Ryan
FIXME: should return the list of invalid recipients.
boolean Send()
triggersE_WARNING
throws Exception, ErrorExceptionCreates 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.
void AddAttachment(string $path, string $name = "", string $encoding = "base64", string $type = "application/octet-stream")Adds an attachment from a path on the filesystem.
$path is the path where the file is stored. $name is the name the recipient of the message will see, possibly different from the base name of the original file $path. $type is the MIME type of the file. This example will add an image as an attachment:
$img = "mypicts/summer/flower.png";
$m->AddAttachment($img, basename($img), "base64", mime_content_type($img));WARNING! Do not rely on the default generic application/octet-stream MIME type, always provide a proper type that match the contents of the file. The function mime_content_type() from the mime_maginc PHP extension does just this.
void AddStringAttachment(string $str, string $filename, string $encoding = "base64", string $type = "application/octet-stream")Adds a string or binary attachment (non-filesystem) to the list.
This method can be used to attach ASCII or binary data, such as a BLOB record from a database.
void AddEmbeddedImage(string $path, string $cid, string $name = "", string $encoding = "base64", string $type = "application/octet-stream")Adds an embedded attachment, typically an image
This can include images, sounds, and just about any other document a mail client can display embedded inside an HTML document. Make sure to set the proper MIME $type. A $name for the file can be provided; it will be proposed to the recipient uses in case he want to save the embedded content into a file. NOTE: probably this method should have been called
AddEmbeddedAttachment()instead, but since images are the typical embedded content, the chosen name seems to be more appropriate.Parameters
$path is the pathfile of the attachment.
$cid is the content ID of the attachment to be used in a URL of the type cid:ID. Every embedded attachment must have a different content ID.
$name overrides the attachment name.
$encoding is the file encoding used to include the file inside the email body, typically "base64" (see $Encoding).
$type is the file MIME type.
Example
$m = new PHPMailer();
$m->IsHTML();
$cid = "1";
$m->Body = "<html><body>Photo: <img src='cid:$cid'> </body></html>";
$m->AddEmbeddedImage("photo.jpg", $cid, "base64", "image/jpeg");void ClearAddresses()Clears all recipients assigned in the TO array.
void ClearCCs()Clears all recipients assigned in the CC array.
void ClearBCCs()Clears all recipients assigned in the BCC array.
void ClearReplyTos()Clears all recipients assigned in the ReplyTo array.
void ClearAllRecipients()Clears all recipients assigned in the TO, CC and BCC array.
void ClearAttachments()Clears all previously set filesystem, string, and binary attachments.
void ClearCustomHeaders()Clears all custom headers.
}
PHPMailer_Attachment
Generated by PHPLint Documentator