WordPress Function To Send Emails

WordPress Function To Send Emails

To send email WordPress uses similar function like mail()  in Php. WordPress function to send emails is wp_mail which uses 5 parameters as following;

Lets see what each of these parameter are responsible for.

$to (required)
Array or string containing recipients. Multiple recipients may be specified using an array or a comma-separated string. This parameter is required
Default: None
$subject (required)
String containing subject of the message. This parameter is required.
Default: None
$message (required)
String containing the message of the email. This is also required parameter.
Default: None
$headers (optional
Array or string containing mail headers to send with the message. $headers is probably easiest to use in its array form. To use it, push a string onto the array, starting with “From:”, “Bcc:” or “Cc:” (note the use of the “:”), followed by a valid email address. Don’t worry if this sounds confusing to you as I have example for this below in example code.
Default: Empty
$attachments (optional)
Array or string containing Files to attach. It can be a single filename, an array of filenames, or a newline-delimited string list of multiple filenames . This one too is optional parameter .
Default: Empty

Now its time to go through a full flash example of its usage.

 

In above example you can see how easy is to use wp_mail function to send emails. By the way don’t get confused with WP_CONTENT_DIR  in attachments array, its just one of WordPress constants. Hope this might help you on your way.

Happy WordPressing!

Share This

Share This

Share this post with your friends!