How To Send Email In WordPress

In this Blog we will learn How to send email when we are using WordPress.

As of now everything works with the Emails. You are also getting so many emails through out your daily routine related to advertisement, promotion, ecommerce, etc.

Now, I am going to show you if in your WordPress site you want to perform the email functionality without any plugin.

I am going to use wp_mail() function which is already exists and performs the email functionality.

Here is the syntax code for wp_mail().

wp_mail( $to, $subject, $body, $headers );

$to => It will represent to whom you wanna send email.

$subject => It will represent which Subject of your email you wanna put.

$body => It will represent the content of your email body. What ever you want to send in your mail content you need to pass into the body.

$header => It will represent which content type you want to add, what should be the from email address, etc.

Here is the reference code you can use.

$to = "";
$subject = "Test Subject";
$body = "Test Content";
$headers = array (
  'From: "Test" <>' ,
  'X-Mailer: PHP/' . phpversion(),
  'MIME-Version: 1.0' ,
  'Content-type: text/html; charset=iso-8859-1'
$headers = implode( "\r\n" , $headers );

$result = wp_mail( $to, $subject, $body, $headers );
echo "<pre>";
echo "</pre>";


To test this function runs or not you can create mail.php file and you can put this code in that file.

Now you need to run that file based on your file path.

I hope it will works as per your need if it’s not feel free to put your questions in comment box.

Thank You.

Submit a Comment

Your email address will not be published. Required fields are marked *


Select Categories