Methods (v5.0.0) | Type | Default | Description |
---|---|---|---|
set($name, $value) | string $name string $value |
Method provides ability for user to create own custom pseudo-properties (like X-Headers, for example). Example use: $mail->set('X-MSMail-Priority', 'Normal'); |
|
addCustomHeader($value) | string $value | Method provides ability for user to create own custom headers (like X-Priority, for example). Example use: $mail->addCustomHeader("X-Priority: 3"); |
|
MsgHTML($message) | Evaluates the message and returns modifications for inline images and backgrounds. Sets the IsHTML() method to true, initializes AltBody() to either a text version of the message or default text. | ||
IsMail() | boolean | true | Sets Mailer to send message using PHP mail() function. (true, false or blank) |
IsSMTP() | boolean | Sets Mailer to send message using SMTP. If set to true, other options are also available. (true, false or blank) | |
IsSendmail() | boolean | Sets Mailer to send message using the Sendmail program. (true, false or blank) | |
IsQmail() | boolean | Sets Mailer to send message using the qmail MTA. (true, false or blank) | |
SetFrom($address, $name = "") | string $address string $name |
Adds a "From" address. | |
AddAddress($address, $name = "") | string $address string $name |
Adds a "To" address. | |
AddCC($address, $name = "") | string $address string $name |
Adds a "Cc" address. Note: this function works with the SMTP mailer on win32, not with the "mail" mailer. | |
AddBCC($address, $name = "") | string $address string $name |
Adds a "Bcc" address. Note: this function works with the SMTP mailer on win32, not with the "mail" mailer. | |
AddReplyTo($address, $name = "") | string $address string $name |
Adds a "Reply-to" address. | |
Send() | 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. Returns true on success, false on failure. | ||
AddAttachment($path, $name = "", $encoding = "base64", $type = "application/octet-stream") |
string $path string $name string $encoding string $type |
Adds an attachment from a path on the filesystem. Returns false if the file could not be found or accessed. | |
AddEmbeddedImage($path, $cid, $name = "", $encoding = "base64", $type = "application/octet-stream") |
string $path string $cid string $name string $encoding string $type |
Adds an embedded attachment. This can include images, sounds, and just about any other document. Make sure to set the $type to an image type. For JPEG images use "image/jpeg" and for GIF images use "image/gif". If you use the MsgHTML() method, there is no need to use AddEmbeddedImage() method. | |
ClearAddresses() | Clears all recipients assigned in the TO array. Returns void. | ||
ClearCCs() | Clears all recipients assigned in the CC array. Returns void. | ||
ClearBCCs() | Clears all recipients assigned in the BCC array. Returns void. | ||
ClearReplyTos() | Clears all recipients assigned in the ReplyTo array. Returns void. | ||
ClearAllRecipients() | Clears all recipients assigned in the TO, CC and BCC array. Returns void. | ||
ClearAttachments() | Clears all previously set filesystem, string, and binary attachments. Returns void. | ||
ClearCustomHeaders() | Clears all custom headers. Returns void. |
Property (v5.0.0) | Type | Default | Description |
---|---|---|---|
$Priority | public | 3 | Email priority (1 = High, 3 = Normal, 5 = low) |
$CharSet | public | iso-8859-1 | Sets the CharSet of the message |
$ContentType | public | text/plain | Sets the Content-type of the message |
$Encoding | public | 8bit | Sets the Encoding of the message. Options for this are "8bit", "7bit", "binary", "base64", and "quoted-printable" |
$ErrorInfo | public | Holds the most recent mailer error message | |
$From | public | root@localhost | Sets the From email address for the message |
$FromName | public | Root User | Sets the From name of the message |
$Sender | public | 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. | |
$Subject | public | Sets the Subject of the message. | |
$Body | public | Sets the Body of the message. This can be either an HTML or text body. If HTML then run IsHTML(true). | |
$AltBody | public | 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. | |
$WordWrap | public | 0 | Sets word wrapping on the body of the message to a given number of characters |
$Mailer | public | Method to send mail: ("mail", "sendmail", or "smtp"). | |
$Sendmail | public | /usr/sbin/sendmail | Sets the path of the sendmail program. |
$PluginDir | public | Path to PHPMailer plugins. This is now only useful if the SMTP class is in a different directory than the PHP include path. | |
$ConfirmReadingTo | public | Sets the email address that a reading confirmation will be sent. | |
$Hostname | public | 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'. | |
$Host | public | localhost | 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. |
$Port | public | 25 | Sets the default SMTP server port. |
$Helo | public | Sets the SMTP HELO of the message (Default is $Hostname). | |
$SMTPAuth | public | false | Sets SMTP authentication. Utilizes the Username and Password variables. |
$Username | public | Sets SMTP username. | |
$Password | public | Sets SMTP password. | |
$Timeout | public | 10 | Sets the SMTP server timeout in seconds. This function will not work with the win32 version. |
$SMTPDebug | public | false | Sets SMTP class debugging on or off. |
$SMTPKeepAlive | public | false | 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(). |
$SingleTo | public | false | Provides the ability to have the TO field process individual emails, instead of sending to entire TO addresses |
<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = '[email protected]'; // SMTP username
$mail->Password = 'secret'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->From = '[email protected]';
$mail->FromName = 'Mailer';
$mail->addAddress('[email protected]', 'Joe User'); // Add a recipient
$mail->addAddress('[email protected]'); // Name is optional
$mail->addReplyTo('[email protected]', 'Information');
$mail->addCC('[email protected]');
$mail->addBCC('[email protected]');
$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}