WireMail class

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.

Show $var?             Show args?        

Common

NameReturnSummary 
$m->body(string $body)
$thisSet the email message body (text only)
Can also be used as property: $m->body
 
$m->bodyHTML(string $body)
$thisSet the email message body (HTML only)
Can also be used as property: $m->bodyHTML
 
$m->from(string $email)
$thisSet the email 'from' address and optionally name
Can also be used as property: $m->from
 
$m->fromName(string $name)
$thisSet the 'from' name
Can also be used as property: $m->fromName
 
$m->get(string $key)
mixed nullGet property 
$m->headers(array $headers)
$thisSet multiple email headers using associative array
Can also be used as property: $m->headers
 
$m->htmlToText($html)
stringConvert HTML email body to TEXT email body.
$m->replyTo(string $email)
$thisSet the 'reply-to' email address and optionally name (where supported)
Can also be used as property: $m->replyTo
 
$m->replyToName(string $name)
$thisSet the 'reply-to' name (where supported)
Can also be used as property: $m->replyToName
 
$m->send()
intSend the email
$m->set(string $key, mixed $value)
this WireDataSet property 
$m->subject(string $subject)
$thisSet the email subject
Can also be used as property: $m->subject
 
$m->to()
$thisSet the email to address
Can also be used as property: $m->to
 
$m->toName(string $name)
$thisSet the 'to' name
Can also be used as property: $m->toName
 

Advanced

NameReturnSummary 
$m->attachment(string $value)
$thisAdd a file to be attached to the email 
$m->attachments array Array of file attachments (if populated and where supported)  
$m->encodeSubject(string $subject)
stringEncode a subject, use mbstring if available 
$m->header($key, string $value)
$thisSet any email header
Can also be used as property: $m->header
 
$m->newline string Newline character, populated only if different from CRLF.  
$m->param(string $value)
$thisSet any email param
Can also be used as property: $m->param
 
$m->quotedPrintableString(string $text)
stringReturn 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:

API reference based on ProcessWire core version 3.0.137

Twitter updates

  • New post: This week we’ll take a look at a new version of FormBuilder that's on the way (with a screencast), as well as the latest version of the core: ProcessWire 3.0.140— More
    6 September 2019
  • We added WebP image support this year and many have been adopting it in existing projects. We look at a process used for migrating existing websites to WebP images— from preliminary considerations to implementation & testing, w/lots of tips & tricks too: More
    16 August 2019
  • Core version 3.0.137 on the dev branch adds the ability to hook multiple methods at once, in a single call. This post details how it works and provides a useful example of how you might put it to use in your development environment— More
    2 August 2019

Latest news

  • ProcessWire Weekly #279
    This week in the 279th issue of ProcessWire Weekly we're going to introduce some of the latest third party modules out there, and highlight a brand new site of the week. Read on!
    Weekly.pw / 14 September 2019
  • ProcessWire 3.0.140 and FormBuilder v40
    This week we’ll take a look at a new version of FormBuilder that's on the way (with a screencast), as well as the latest version of the core: ProcessWire 3.0.140.
    Blog / 6 September 2019
  • Subscribe to weekly ProcessWire news

“I am currently managing a ProcessWire site with 2 million+ pages. It’s admirably fast, and much, much faster than any other CMS we tested.” —Nickie, Web developer