WireMail class

A module type that handles sending of email in ProcessWire

Below are 2 different ways you can get a new instance of WireMail.

$m = $mail->new(); // option A: use $mail API variable
$m = wireMail(); // option B: use wireMail() function

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('Optional message body in plain text')
  ->bodyHTML('<html><body><p>Optional message body in HTML</p></body></html>')
  ->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->fromName('Mary Jane');
$m->toName('John Smith');
$m->replyTo('somebody@somewhere.com');
$m->replyToName('Joe Somebody');
$m->attachment('/path/to/file.ext');
$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();

There are 1 WireMail types in the core, plus many more WireMail modules in our directory.

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?       Only hookable?    

Common

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

Advanced

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

Core WireMail types

See also: WireMail modules in the modules directory

API reference based on ProcessWire core version 3.0.251