2

I am breaking my head from last 1 hour but not getting any idea that what's going wrong with my code...

I am developing my own plugin and I am using wp_mail() function for sending mail in that but it's not sending mail it seems.

I tried to use PHP Mailer which is working fine but I want to use wp_mail().. this is my code..

  $from = "abc@gmail.com";
    $headers[] = "From:" . $from;
    $send = wp_mail("myemail@gmail.com", "hiii", "hiiii",$headers);
      if($send) {
          echo "send";
        return false;
       } else {
           echo $send;
        return true;
       }

Can any body help me to figure out my mistake... I am testing it on my server only...

Thanks in advance.

  • Are you aware that you use $headers and $header spellt differently? I do not understand what you wnat to achieve with your conditional. It returns false if the email is sent? – fischi Jan 27 '14 at 10:58
  • $headers and $header is printing mistake here.. sorry for that.. and regarding true and false pls ignore it here... – user41362 Jan 27 '14 at 11:02
2

Since PHP Mailer is working fine do you have the same credentials setup for wp_mail? If you're using an authenticated SMTP for PHP Mailer then you'll possibly need a plugin to get the authentication into wp_mail. There are a few different ones that all work but one is https://wordpress.org/plugins/wp-mail-smtp/ for example.

0

Try using the $headers as a string, and giving a name to the email.

$headers = 'From: Your Name <abc@gmail.com>' . "\r\n";

Do not forget to add the \r\n like in the code above if you are using the string version.

If this does not work, try using wp_mail without additional headers, and check if it works. Should be sorted then :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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