How to use wp_mail() function in wordpress

Selva Kumar picture Selva Kumar · Oct 6, 2016 · Viewed 34.1k times · Source

<?php
if (isset($_POST['sbt'])) {
//user posted variables
  $name = $_POST['name'];
  $email = $_POST['email'];
  $message = $_POST['message'];

//php mailer variables
  $to = get_option('[email protected]');
  $subject = "Report";
  $headers = 'From: '. $email . "\r\n" .
    'Reply-To: ' . $email . "\r\n";

echo "check";

//Here put your Validation and send mail
$sent = wp_mail($to, $subject, strip_tags($message), $headers);
      if($sent) {
      echo "sent";
      }//mail sent!
      else  {
      echo "failed";
      }//message wasn't sent
}
?>

I have developed a own word press site i need to use WP_mail() function to my contact form.

please help me.

Answer

JanuszO picture JanuszO · Oct 6, 2016

this is example:

//user posted variables
  $name = $_POST['message_name'];
  $email = $_POST['message_email'];
  $message = $_POST['message_text'];

//php mailer variables
  $to = get_option('admin_email');
  $subject = "Some text in subject...";
  $headers = 'From: '. $email . "\r\n" .
    'Reply-To: ' . $email . "\r\n";
 }

//Here put your Validation and send mail
$sent = wp_mail($to, $subject, strip_tags($message), $headers);
      if($sent) {

      }//message sent!
      else  {

      }//message wasn't sent