1

Why WP prevent me from sending mail?

I created a file mail.php and tested the PHP mail():

$to = "somebody@example.com";
$subject = "My subject";
$txt = "Hello world!";
$headers = "From: webmaster@example.com" . "\r\n" .
"CC: somebodyelse@example.com";

mail($to,$subject,$txt,$headers);

I uploaded it my server, in the root directory. I run it and I received emails with that.

But when I use

$message = trim($_POST['sender_message']);
$email = trim($_POST['sender_email']);

//php mailer variables
$to = get_option('admin_email');
$subject = "Someone sent a message from ". get_bloginfo('name') . ": " . $subject;
$headers = 'From: '. $email . "\r\n" .
  'Reply-To: ' . $email . "\r\n";

// $sent = wp_mail($to, $subject, strip_tags($message), $headers); 
$sent = mail($to, $subject, strip_tags($message), $headers);
var_dump($send); // bool true
if($sent) { 
 // do something
}

I get bool true in the var_dump check. But I never received any email from my server.

Any ideas? Have I missed something to configure in WP?

EDIT:

The server won't send any email from yahoo accounts! Why???

$to = "xxx@yahoo.co.uk"; // works!
$subject = "My subject";
$txt = "Hello world!";
$headers = "From: bbb@yaho.co.uk" . "\r\n" . // won't work!
"CC: lau.tiamkok@gmail.com";

mail($to,$subject,$txt,$headers);
Run
  • 54,938
  • 169
  • 450
  • 748
  • Have you tried printing out the value of `$to` / `get_option('admin_email')` to ensure it is what you expect it to be? – Jack Wilsdon Jul 09 '16 at 03:51
  • yes it is the correct output. It is caused by `@yahoo.co.uk`. the server won't send any email from `yahoo` accounts! – Run Jul 09 '16 at 04:04
  • Didn't it end up in the spam folder? – tvdpol Jul 09 '16 at 06:14
  • @tvdpol no it didn't. – Run Jul 09 '16 at 06:27
  • here some problem to send email from php mail function...... their has some issues like SMTP issue ... so if you want to successfully send email i think you may use PHPMailer function ..https://github.com/PHPMailer/PHPMailer – Nadimul De Cj Jul 09 '16 at 06:36

0 Answers0