0

I'm spent the last hour trying to figure out why the wp_mail function is returning a false boolean.

Here's my code. I can usually get this to work but can't seem to figure it out now. I'm thinking this has something to do with my server settings.

Thanks for the help.

<?php

  $mail ='';
  $errors = '';

  if(isset($_REQUEST['contact_submit'])) {
    $contact_name = $_REQUEST['contact_name'];
    $contact_email = $_REQUEST['contact_email'];
    $contact_subject = $_REQUEST['contact_subject'];
    $contact_message = $_REQUEST['contact_message'];

    $errors = '';
    // Checking if vars are all filled

    if ( $contact_name != '' && $contact_email != '' && $contact_subject != '' && $contact_message != '' ) {

      $to = '[email protected]';
      $subject = 'Contact Form Submission';
      $body = '<html><body><table>';

      if($contact_name) $body .= '<tr><td><strong>Name: </strong></td><td>'.$contact_name.'</td></tr>';
      if($contact_email) $body .= '<tr><td><strong>Email: </strong></td><td>'.$contact_email.'</td></tr>';
      if($contact_subject) $body .= '<tr><td><strong>Phone Number: </strong></td><td>'.$contact_subject.'</td></tr>';
      if($contact_message) $body .= '<tr><td><strong>Message: </strong></td><td>'.$contact_message.'</td></tr>';

      $body .= '</table></body></html>';
      $headers = 'From: ' . $contact_name . ' <' . $contact_email . '>' . "\r\n";
      $headers .= 'Content-type: text/html' . "\r\n";
      $mail =     wp_mail( $to, $subject, $body, $headers );
    } else {
      $errors = 'Please fill out all fields';
    }
}

?>

1 Answer 1

0

Your code looks okay to me. Instead check whether email working in other part of the website or not!! Use Postman SMTP Mailer/Email Log plugin to configure / test / debug your mail system.

3
  • Any update here? Commented Feb 5, 2016 at 14:06
  • I think it had something to do with the headers and namecheap's server setting. Form works without including the $headers for some reason.
    – Peekay
    Commented Mar 2, 2016 at 20:29
  • 1
    After further research, namecheap will only allow you to use a "to" email that is registered on their server.
    – Peekay
    Commented Mar 16, 2016 at 0:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.