Vishnu Sharma
Vishnu Sharma

Reputation: 49

PHP Mail() function not working in cpanel hosting

The PHP mail() function is not working from my cpanel.

My cpanel ports are all open and by default the email ID is also set in cpanel.

MY code

$to = "[email protected]";
$subject = "My subject"; 
$txt = "Hello world!";
$headers = "From: [email protected]" ;
mail($to,$subject,$txt,$headers);

Upvotes: 3

Views: 20689

Answers (3)

Enrico Dias
Enrico Dias

Reputation: 1487

Your code seems correct, but most hosts block the mail function by default and/or prevent the user nobody from sending emails.

In Tweak Settings on WHM, try turning off the option "Prevent 'nobody' from sending mail".

In the PHP Configuration Editor (in advanced mode) check if the mail function is listed in the disable_functions directive.

If none of that work, check if the Exim is up and running and if the sendmail_path in php.ini is correct.

Upvotes: 3

SHAHLA THASNI
SHAHLA THASNI

Reputation: 1

ini_set( 'display_errors', 1 );
error_reporting( E_ALL );

$from = "[email protected]";
$to = "[email protected]";

$subject = "PHP Mail Sending Checking";
$message = "PHP Mail Works Fine";
$headers = "From: " . $from;

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

Upvotes: 0

Drey
Drey

Reputation: 387

In my case there was an apache misconfiguration. I saw in logs only this unable to set gid=993 or uid=0 (euid=0): forcing real = effective And the fix was to add LimitUIDRange 0 2000 to apache mpm_prefork.conf file and restart apache

Upvotes: 0

Related Questions