A module type that handles sending of email in ProcessWire

Below are 3 different ways you can get a new instance of WireMail. When possible we recommend using option A or B below.

$m = $mail->new(); // option A
$m = wireMail(); // option B
$m = new WireMail(); // option C

Once you have an instance of WireMail ($m), you can use it to send email like in these examples below.

// chained (fluent) method call usage
$m->to('user@domain.com')
  ->from('you@company.com')
  ->subject('Message Subject')
  ->body('Message Body')
  ->send();

// separate method call usage
$m->to('user@domain.com'); // specify CSV string or array for multiple addresses
$m->from('you@company.com'); 
$m->subject('Message Subject'); 
$m->body('Message Body'); 
$m->send();

// optionally specify “from” or “to” names as 2nd argument 
$m->to('user@domain.com', 'John Smith');
$m->from('you@company.com', 'Mary Jane'); 

// other methods or properties you might set (or get)
$m->bodyHTML('<html><body><h1>Message Body</h1></body></html>'); 
$m->attachment('/path/to/file.ext'); 
$m->fromName('Mary Jane');
$m->toName('John Smith');
$m->header('X-Mailer', 'ProcessWire'); 
$m->param('-f you@company.com'); // PHP mail() param (envelope from example)

// note that the send() function always returns the quantity of messages sent
$numSent = $m->send();

Click any linked item for full usage details and examples. Hookable methods are indicated with the icon. In addition to those shown below, the WireMail class also inherits all the methods and properties of: WireData and Wire.

Common / Advanced

Common

Name Return Summary  
WireMail::body(string $body) $this Set the email message body (text only)
Can also be used as property: WireMail::body
WireMail::bodyHTML(string $body) $this Set the email message body (HTML only)
Can also be used as property: WireMail::bodyHTML
WireMail::from(string $email) $this Set the email from address
Can also be used as property: WireMail::from
WireMail::fromName($name) $this Set the 'from' name
Can also be used as property: WireMail::fromName
WireMail::send() int Send the email
WireMail::subject(string $subject) $this Set the email subject
Can also be used as property: WireMail::subject
WireMail::to() $this Set the email to address
Can also be used as property: WireMail::to
WireMail::toName($name) $this Set the 'to' name
Can also be used as property: WireMail::toName

Advanced

Name Return Summary  
WireMail::attachment(string $value) $this Add a file to be attached to the email
WireMail::attachments array Array of file attachments (if populated)
WireMail::encodeSubject(string $subject) string Encode a subject, use mbstring if available
WireMail::header(string $key, string $value) $this Set any email header
Can also be used as property: WireMail::header
WireMail::param(string $value) $this Set any email param
Can also be used as property: WireMail::param
WireMail::quotedPrintableString(string $text) string Return the text quoted-printable encoded

Additional methods and properties

In addition to the methods and properties above, WireMail also inherits the methods and properties of these classes: