Reputation: 1163
php mail is not working. no error messages. php.ini has display errors on and show E_ALL is also on.
<?php
$to = "[email protected]";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
$headers = 'From: [email protected]' . "\r\n" .
'Reply-To: [email protected]' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $body, $headers);
?>
Upvotes: 1
Views: 2181
Reputation: 92792
First of all, check the return value of mail()
$sent = mail($to, $subject, $body, $headers);
if (!$sent) {
// there was some error in the message itself, our MTA rejected it or there's an error in MTA's config
} else {
// message was accepted for delivery
}
Second, check PHP's e-mail settings (note that on a Linux server the sendmail_path
is relevant, whereas on Windows servers it's SMTP
and smtp_port
) try to send an e-mail with them from another application.
Third, depending on the SMTP server you use, check its logs for any warnings or errors (e.g. cannot contact destination server, not connected to network, etc.).
Fourth, if you have ascertained that the mail has succesfully left your network, cross your fingers and hope for the best. Seriously, there's nothing more that you can do for your e-mail message from that point onwards - and if it doesn't get delivered, there's not much you can do.
Check out also these tips on slightly increasing the chance that your mail won't be marked as spam
Upvotes: 2
Reputation: 1163
Thank you all so much for the replies. It was really helpful. It was a permission issue
drwxrwx--- 2 smmsp smmsp 4096 Oct 12 12:00 /var/spool/clientmqueue/
changed above to
drwxrwx--- 2 apache smmsp 4096 Oct 12 12:56 /var/spool/clientmqueue/
and it worked!
Upvotes: 2