Recommend this page to a friend! |
Classes of Christian Vigh | PHP Mail Sending | README.md | Download |
|
DownloadINTRODUCTIONThe Mail class is yet-another PHP mailer, with the following features :
DEPENDENCIESThe Mail* class requires the Adavanced Regex package, located here :
File Regex.class.php has been provided here for your convenience, but this may not be the latest version. EXAMPLESYou can have a look at the examples/ directory, to have an overview of the various usages of this class. The file examples/README.md explains how the examples are organized, and which example does what. The basic usage of the Mail class is fairly simple ; the following example will send a plain text mail with subject "Mail subject", and contents "Mail contents", to the address "someone@example.com" :
An exception will be thrown if something goes wrong. REFERENCEMETHODSConstructorThe Mail class constructor has the following signature :
It creates an instance of the class, and any parameters defined in the constructor can be specified later by using properties. Parameters are the following
$mail -> AddRecipient ( $addresses... )Adds the specified addresses to the recipient list. The function's parameters can be any number of strings or arrays of strings containing the addresses. Duplicate addresses will be ignored. Example :
You can also manually append addresses to the To property but in this case, there will be no checking on duplicates :
$mail -> AddCC ( $addresses... )Adds addresses to Carbon Copy recipients. Behaves as the AddRecipient() method. You can also manually append addresses to the CC property. $mail -> AddBCC ( $addresses... )Adds addresses to Blind Carbon Copy recipients (ie, the recipients added by the AddRecipient() and AddCC() methods won't know that there are additional recipients specified as BCC). Behaves as the AddRecipient() method. You can also manually append addresses to the BCC property. $mail -> AddMimeHeader ( $name, $value, $replace = true ) ;Adds a MIME header or replaces an existing one. $mail -> AddAttachment ( $path, $name = false )Adds an attachment to the current mail. The $name parameter indicates the attachment file name that will be shown to the recipient when he will open its mail. If not specified, the filename portion of the $path parameter will be used. $contents = $mail -> GetContents ( ) ;Returns the mail contents as plain text, including MIME headers, text and base64-encoded attachments. $mail -> LoadHtml ( $file, $base\_path = false ) ;Html contents can be specified in two ways : either by specifying some value for the $html parameter of the class constructor, or setting later the Html property. The LoadHtml() method provides a third way to load html contents, from an external file. This file can be a regular html page using <html>, <head> and <body> tags (or not) ; the following contents will be extracted from it to form the mail's html part :
The $base\_path parameter indicates the root path for searching external images referenced by html contents. $mail -> Send ( ) ;Sends the mail using the standard PHP mail() function. An exception will be thrown if something goes wrong. $mail -> Validate ( ) ;Validates an email by verifying the following elements :
It also provides default values for certain fields :
PROPERTIESBCCAn array containing the Blind Carbon Copy recipients. The preferred way of adding new BCC recipients is by using the AddBCC() method, which performs additional checkings, such as ignoring duplicate addresses. CCAn array containing the Carbon Copy recipients. The preferred way of adding new CC recipients is by using the AddCC() method, which performs additional checkings, such as ignoring duplicate addresses. DestinatioCharsetMIME character set used for building mail contents. The default is ISO8859-1. ErrorsToEmail address where error messages coming from mail servers will be sent. FromSender's email address. HtmlHtml part of the mail contents. HtmlBasePathBase path to be used for retrieving images referenced by the html contents. ReplyToEmail address to be used when the recipient will reply to the mail. ReturnPathEmail address for the return path. ReturnReceiptToEmail address to be used for read receipts. SourceCharsetCharacter set used in the source html contents. SubjectMail subject. TextPlain text part of the message contents. ToAn array containing the list of recipients. The preferred way of adding new recipients is by using the AddRecipient() method, which performs additional checkings, such as ignoring duplicate addresses. |