Viet Nguyen
Viet Nguyen

Reputation: 2373

PHP mail() send error but not report error

i'm running CentOS 64bit, install php 5.3.3 and i have php code like this

<?php
session_start(); 
set_time_limit(0);
ini_set("max_execution_time", 1800);
ini_set("display_errors", 1);
error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING);
date_default_timezone_set('Asia/Saigon');

mail("[email protected]","x","y","From: [email protected]\n");
?>

Email not sent but also not reporting any error, i will edit in php.ini

error_reporting = E_ALL & ~E_NOTICE & ~E_WARNING
display_errors = On

Still no have error reporting...

Please help.

Upvotes: 0

Views: 107

Answers (1)

Ashesh Kumar
Ashesh Kumar

Reputation: 223

This is because of Spf protection. Try the below code and it'll work

<?php
session_start(); 
set_time_limit(0);
ini_set("max_execution_time", 1800);
ini_set("display_errors", 1);
error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING);
date_default_timezone_set('Asia/Saigon');

mail("[email protected]","x","y","From: [email protected]\n");
?>

I replaced apple.com with air.com You can't use some domains like

  1. [email protected]
  2. [email protected] etc.

in php mail() as They are protected by Sender Policy Framework (SPF) but if you want you can use this and it'll work for any domain:

<?php
session_start(); 
set_time_limit(0);
ini_set("max_execution_time", 1800);
ini_set("display_errors", 1);
error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING);
date_default_timezone_set('Asia/Saigon');

mail("[email protected]","x","y","From: steve@ apple.com\n");
?>

@ Note the space between @and apple.com but by using this method you can't send mail to Yahoo users. The best option is to buy a SMTP server to send mail peacefully!

Read more here: https://workaround.org/ispmail/lenny/spf

Upvotes: 2

Related Questions