Portal Home > Knowledgebase > Articles Database > mail not sending externally


mail not sending externally




Posted by Allan87, 01-07-2009, 05:16 PM
php $to = "user@domain.com"; $subject = "Testing"; $message = "Testing the server php mail function"; $headers = 'From: sender@domain.com' . "\r\n" . 'Reply-To: sender@domain.com' . "\r\n" . 'x-mailer: php/' . phpversion(); mail($to, $subject, $message, $headers); echo "success?"; ?>Can anyone suggest why the above code isn't sending mail externally?

Posted by larwilliams, 01-07-2009, 07:07 PM
php $to = "user@domain.com"; $subject = "Testing"; $message = "Testing the server php mail function"; $headers = 'From: sender@domain.com' . "\r\n" . 'Reply-To: sender@domain.com' . "\r\n" . 'x-mailer: php/' . phpversion(); mail($to, $subject, $message, $headers); echo "success?"; ?>Can anyone suggest why the above code isn't sending mail externally? Without more details (like where it is being sent), I would say it is one of 2 things: 1) spam filtering on the recipient end. The headers you are sending are not sufficient for most receiving servers. 2) Your headers are triggering a restriction in your mail server (such as an Exim option that prevents scripts from sending e-mail with the Sender: set to "nobody").

Posted by fava, 01-07-2009, 07:25 PM
Do you have access to the log files? check /var/log/mail, although it might be /var/log/something-else depending how your server is set up. fava

Posted by BHWebStudio, 01-15-2009, 10:26 AM
Try adding your web site's IP address to trusted senders list on your mail server. I hope this helps. BR, Faik

Posted by jaseeey, 01-15-2009, 11:18 AM
It could also be that your SMTP servers require authentication in order to send mail out There are ways to do this if it is the cause.

Posted by Vinayak_Sharma, 01-15-2009, 05:19 PM
If you are running that script on a cPanel server possibility is that nobody mail tweak is enabled under Main >> Server Configuration >> Tweak Settings: Prevent the user "nobody" from sending out mail to remote addresses (PHP and CGI scripts generally run as nobody if you are not using PHPSuexec and Suexec respectively.) If that is your own server disable nobody tweak or ask your host if they have it enabled.

Posted by larwilliams, 01-15-2009, 05:59 PM
If you are running that script on a cPanel server possibility is that nobody mail tweak is enabled under Main >> Server Configuration >> Tweak Settings: If that is your own server disable nobody tweak or ask your host if they have it enabled. Or he could simply just fix the code. "nobody" is a major spam target, and I am speaking from our experience as a host. Seeing as he is using PHP, he could simply modify his script to use PHPMailer and SMTP authentication (needs a valid SMTP account on the server) and that will solve that problem at least.

Posted by domaincart, 01-15-2009, 06:12 PM
You can do it by using PHPMailer(http://phpmailer.codeworxtech.com/). It's free and open source. You can define settings as your needs/server easily.

Posted by Hildy, 01-15-2009, 07:57 PM
You might also want to consider using SwiftMailer ( http://swiftmailer.org/ ). It's the one we use for sending mail, and we generally like it. Just about my only complaint on it is that it doesn't throw exceptions when the message fails to send for valid reasons (relaying denied, etc), it just returns false.

Posted by iPublications, 01-15-2009, 08:39 PM
Do you get a PHP error or does it seem to work, but doesn't the mail arrive at all? Try: if(mail(... , ... , ... , ...)){ echo "Sent OK (Says PHP"; }else{ echo "PHP says: NOT OK!"; } ... But it's probably the config of the webserver.



Was this answer helpful?

Add to Favourites Add to Favourites    Print this Article Print this Article

Also Read
Rate Donhost (Views: 480)