A module type that handles sending of email in ProcessWire
Below are 2 different ways you can get a new instance of Wire
$m = $mail->new(); // option A: use $mail API variable
$m = wireMail(); // option B: use wireMail() function
Once you have an instance of Wire$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();
Click any linked item for full usage details and examples. Hookable methods are indicated with the icon. In addition to those shown below, the Wire
class also inherits all the methods and properties of: WireData and Wire.
Common
Name | Return | Summary | |
---|---|---|---|
$m->body() $m->body(string $body) $m->body(string $body) | $this | Set the email message body (text only) Can also be used as property: $m->body | |
$m->bodyHTML() $m->bodyHTML(string $body) $m->bodyHTML(string $body) | $this | Set the email message body (HTML only) Can also be used as property: $m->bodyHTML | |
$m->from() $m->from(string $email) $m->from(string $email, $name = null) | $this | Set the email 'from' address and optionally name Can also be used as property: $m->from | |
$m->fromName() $m->fromName(string $name) $m->fromName(string $name) | $this | Set the 'from' name Can also be used as property: $m->fromName | |
$m->get() $m->get(string $key) $m->get(string $key) | mixed null | Get property | |
$m->headers() $m->headers(array $headers) $m->headers(array $headers) | $this | Set multiple email headers using associative array Can also be used as property: $m->headers | |
$m->htmlToText() $m->htmlToText($html) $m->htmlToText($html) | string | Convert HTML email body to TEXT email body. | |
$m->replyTo() $m->replyTo(string $email) $m->replyTo(string $email, $name = null) | $this | Set the 'reply-to' email address and optionally name (where supported) Can also be used as property: $m->replyTo | |
$m->replyToName() $m->replyToName(string $name) $m->replyToName(string $name) | $this | Set the 'reply-to' name (where supported) Can also be used as property: $m->replyToName | |
$m->send() $m->send() $m->send() | int | Send the email | |
$m->set() $m->set(string $key, mixed $value) $m->set(string $key, mixed $value) | this WireData | Set property | |
$m->subject() $m->subject(string $subject) $m->subject(string $subject) | $this | Set the email subject Can also be used as property: $m->subject | |
$m->to() $m->to() $m->to($email = null, string $name = null) | $this | Set the email to address Can also be used as property: $m->to | |
$m->toName() $m->toName(string $name) $m->toName(string $name) | $this | Set the 'to' name Can also be used as property: $m->toName |
Advanced
Name | Return | Summary | |
---|---|---|---|
$m->attachment() $m->attachment(string $value) $m->attachment(string $value, string $filename = '') | $this | Add a file to be attached to the email | |
$m->attachments | array | Array of file attachments (if populated and where supported) | |
$m->encodeSubject() $m->encodeSubject(string $subject) $m->encodeSubject(string $subject) | string | Encode a subject, use mbstring if available | |
$m->header() $m->header($key, string $value) $m->header($key, string $value) | $this | Set any email header Can also be used as property: $m->header | |
$m->newline | string | Newline character, populated only if different from CRLF. | |
$m->param() $m->param(string $value) $m->param(string $value) | $this | Set any email param Can also be used as property: $m->param | |
$m->quotedPrintableString() $m->quotedPrintableString(string $text) $m->quotedPrintableString(string $text) | string | Return the text quoted-printable encoded |
Additional methods and properties
In addition to the methods and properties above, Wire
API reference based on ProcessWire core version 3.0.244