All Projects → anthonybudd → WP_Mail

anthonybudd / WP_Mail

Licence: MIT license
Send Templated emails with WordPress

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to WP Mail

fregata
A self hosted REST API for message delivery
Stars: ✭ 19 (-78.41%)
Mutual labels:  smtp
parse-smtp-template
Parse Server Module to easy send emails via SMTP with a customizable template option
Stars: ✭ 18 (-79.55%)
Mutual labels:  smtp
Smtp-cracker
[NEW] : Simple Mail Transfer Protocol (SMTP) CHECKER - CRACKER Tool V2
Stars: ✭ 67 (-23.86%)
Mutual labels:  smtp
Mailozaurr
Mailozaurr is a PowerShell module that aims to provide SMTP, POP3, IMAP and probably some other ways to interact with Email. Underneath it uses MimeKit and MailKit libraries written by Jeffrey Stedfast.
Stars: ✭ 107 (+21.59%)
Mutual labels:  smtp
imail
small mail server
Stars: ✭ 88 (+0%)
Mutual labels:  smtp
email-actions
email-actions is a tiny SMTP server with a rules based engine to trigger any actions (notifications/commands etc) based on the emails sent to this server
Stars: ✭ 31 (-64.77%)
Mutual labels:  smtp
imap-honey
IMAP or SMTP honeypot written in Golang
Stars: ✭ 22 (-75%)
Mutual labels:  smtp
mnm-hammer
mnm implements TMTP protocol. Let Internet sites message members directly, instead of unreliable, insecure email. Contributors welcome! (Client)
Stars: ✭ 66 (-25%)
Mutual labels:  smtp
f3-mailer
Fat-Free Sugar Mailer Plugin
Stars: ✭ 18 (-79.55%)
Mutual labels:  smtp
Matrix-EmailBridge
A bridge written in Golang to receive and write emails in matrix
Stars: ✭ 101 (+14.77%)
Mutual labels:  smtp
mailck
golang library for smtp based email validation
Stars: ✭ 53 (-39.77%)
Mutual labels:  smtp
SimpleKotlinMail
A simple, coroutine based Kotlin Email API for both client- and server-side projects
Stars: ✭ 56 (-36.36%)
Mutual labels:  smtp
share
A collection of libraries and tools written in Go.
Stars: ✭ 35 (-60.23%)
Mutual labels:  smtp
messages
A python package designed to make sending messages easy and efficient!
Stars: ✭ 38 (-56.82%)
Mutual labels:  smtp
crystal-email
Simple e-mail sending library
Stars: ✭ 110 (+25%)
Mutual labels:  smtp
aws-lambda-node-mailer
NodeJs code for Firing Email via AWS-Lambda and SES
Stars: ✭ 24 (-72.73%)
Mutual labels:  smtp
blackhole
Blackhole is an MTA written on top of asyncio, utilising async and await statements that dumps all mail it receives to /dev/null.
Stars: ✭ 61 (-30.68%)
Mutual labels:  smtp
Galleon
A badass SMTP mail server built on Node to make your life simpler.
Stars: ✭ 14 (-84.09%)
Mutual labels:  smtp
Log-mailer
Log mailer is a program I made to email log files.
Stars: ✭ 46 (-47.73%)
Mutual labels:  smtp
go-mail
📧 A cross platform mail driver for GoLang. Featuring Mailgun, Postal, Postmark, SendGrid, SparkPost & SMTP.
Stars: ✭ 169 (+92.05%)
Mutual labels:  smtp

WP_Mail - Send Dynamic Templated Emails with WordPress

WP_Mail is the most popular, simplest and powerful dynamic email class available for WordPress. The class provides simple methods for attaching files, custom headers and lots of helper functions. The class only sends emails using the WordPress function wp_mail() , this means that all of your existing SMTP settings will continue to work with no additional config or set-up required.

$email = WP_Mail::init()
    ->to('[email protected]')
    ->subject('WP_Mail is great!')
    ->template(get_template_directory() .'/emails/demo.php', [
        'name' => 'Anthony Budd',
        'location' => 'London',
        'skills' => [
           'PHP',
           'AWS',
        ] 
    ])
    ->send();

email.html

<h3>You have a new contact from enquirey!</h3><br>

<p>
  <strong>Name:</strong><?= $name ?>
</p>

<p>
  <strong>email:</strong>
  <a href="mailto:<?= $email ?>"><?= $email ?></a>
</p>

<p>
  <strong>Skills:</strong><br>
  <ul>
    <?php foreach($skills as $skill): ?>
      <li>
        <?= $skill ?>
      </li>
    <?php endforeach;?>
  </ul>
</p>

Installation

Require WP_Mail with composer

$ composer require anthonybudd/WP_Mail

Or

Download the WP_Mail class and require it at the top of your functions.php file.

    require 'src/WP_Mail.php';

Methods

to(), cc(), bcc()

All of these functions allow you to set an array or string of recipient(s) for your email as shown in the example below.

    $email = WP_Mail::init()
        ->to([
            '[email protected]'
            '[email protected]'
        ])
        ->cc('[email protected]')

subject()

To set the subject field use the subject function. The first argument will be the emails subject.

    $email = WP_Mail::init()
        ->subject('This this the subject')

from()

To set the from header there is a useful helper function.

    $email = WP_Mail::init()
        ->from('John Doe <[email protected]>')

attach()

Similar to the to, cc and bcc, methods the attach method can accept a string or array of stings. This strings must be absolute file paths, this method will throw if the file does not exist.

    $email = WP_Mail::init()
        ->attach(ABSPATH .'wp-content/uploads/2017/06/file.pdf')

template($templatePath, $variables = [])

The templet method is for setting the path to the html email template. The second argument is for an asoc array where the keys will correspond to your HTML email’s variables. Variables are optional and are not required for templates that do not have any variables.

    $email = WP_Mail::init()
        ->template(get_template_directory() .'/email.html', [
           'name' => 'Anthony Budd',
           'job'  => 'Developer',
        ])

templateHeader($templatePath, $variables = [])

templateFooter($templatePath, $variables = [])

Self-explanatory

If you are sending many emails the beforeTemplate() and afterTemplate() will allow you to append and prepen templated HTML to your emails.

    $email = (new WP_Mail)
        ->beforeTemplate(get_template_directory() .'/email-header.html')
		->afterTemplate(get_template_directory() .'/email-footer.html')
        ->template(get_template_directory() .'/email.html', [
           'name' => 'Anthony Budd',
           'job'  => 'Developer',
        ])

headers()

This method allows you to set additional headers for your email. This can be an array of headers or a single string header.

    $email = WP_Mail::init()
        ->headers("From: John Doe <[email protected]>")
    $email = WP_Mail::init()
        ->headers([
            "From: John Doe <[email protected]>",
            "X-Mailer: PHP/". phpversion(),
            "Reply-To: [email protected]",
            "Content-type: text/html; charset=iso-8859-1",
        ])

render()

This method is called by the send() method, the result is given directly to the $message argument of the wp_mail function. This can be used for testing or for displaying what an email will look like for admins.

The render() method is called when you send an email will use a simple bit of regex to find and replace variables using a mustache-esque syntax. Finally the method sends the email using WordPresses built in wp_mail() function.

    $email = (new WP_Mail)
        ->send()
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].