HowTo – Sending Mail Within WordPress

Filed under: Wordpress Tips

wordpress_logoThere are times when you need mail if you are writing or altering a plugin or maybe you have a special feature you are adding. Heck maybe you want to hook into the login and get an email everytime someone logs in…

Hey thats not a bad idea ..

Well instead of writing your own php mailer or using someone elses code you can do it through WordPress with wp_mail

The function is pretty straight forward with only a few options that need to be filled in to work.

Parameters

$to
(string) (required) The intended recipient(s) of the message.

Default: None

$subject
(string) (required) The subject of the message.

Default: None

$message
(string) (required) Message content.

Default: None

$headers
(string) (optional) Mail headers to send with the message (advanced)

Default: Empty

Usage

<?php wp_mail($to, $subject, $message, $headers = ); ?>

Remember to use clean vars