Send E Mails with WordPress

For a Project at work I had to implement a solution where [[Wordpress]] sends automated E Mails. In the end it was very easy but it was quite some digging trough the Codex to find what I needed, so I thought I share my work here.

All Magic happens in the functions.php file of your template, where else 😉

It all comes down to the wp_mail function
wp_mail($to, $subject, $message, $headers);

  • $to – is the string or array with recipient E Mail addresses
  • $subject – is the subject line
  • $message – the E Mail body
  • $header – is the an array for all E Mail Settings

everything pretty straight forward. The Headers array has some easy to use Settings:

  • $headers[] = “Content-type: text/html”; – makes your E Mail an HTML Mail
  • $headers[] = “From: The Sender <test@test.org>; – sets the Senders E Mail address

That’s all the Fun. Call that with any hook and your WordPress installation sends E Mails like magic (If you have a sendmail handler activated on your server but that’s another story).

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s