samona Posted July 17, 2008 Share Posted July 17, 2008 Hi, I'm trying to send email using PHP and a remote Windows smtp server. I changed my php.ini file to point to the ip address of the server and set the From settings. The next thing I did was: 1. Upload the script <?php $to = "[email protected]"; $subject = "Hi!"; $body = "Hi,\n\nHello World!"; if (mail($to, $subject, $body)) { echo("<p>Message successfully sent!</p>"); } else { echo("<p>Message delivery failed...</p>"); } ?> 2. I uploaded the script to my server. 3. I opened the page where the script is located and I get an error saying Message delivery failed... What am I doing wrong? Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/115231-mail-function/ Share on other sites More sharing options...
JD* Posted July 17, 2008 Share Posted July 17, 2008 Does your server require authentication? Quote Link to comment https://forums.phpfreaks.com/topic/115231-mail-function/#findComment-592463 Share on other sites More sharing options...
ag3nt42 Posted July 17, 2008 Share Posted July 17, 2008 did you use smtp.SERVERIP.com/net/org ? or just SERVERIP for the smtp loc? @JD* I've never seen anything about having to use authentication.. how and where would you set that up? Quote Link to comment https://forums.phpfreaks.com/topic/115231-mail-function/#findComment-592474 Share on other sites More sharing options...
PFMaBiSmAd Posted July 17, 2008 Share Posted July 17, 2008 Add the following two lines after your first opening <?php tag to get php to help you find why the mail() function call failed - ini_set ("display_errors", "1"); error_reporting(E_ALL); Unless your IP address is "trusted" by the remote mail server, it will typically require that you authenticate against an email account on that server using SMTP Authentication (the same as if you were using a email client like Outlook.) The mail() function does not support SMTP Authentication. You would need to use something like the phpmailer class, which opens a socket connection with the mail server and exchanges STMP commands. Quote Link to comment https://forums.phpfreaks.com/topic/115231-mail-function/#findComment-592485 Share on other sites More sharing options...
JD* Posted July 17, 2008 Share Posted July 17, 2008 @ag3nt42 - See PFMaBismAd...that's what I was getting at. Quote Link to comment https://forums.phpfreaks.com/topic/115231-mail-function/#findComment-592486 Share on other sites More sharing options...
ag3nt42 Posted July 17, 2008 Share Posted July 17, 2008 interesting..so in order to be able to authenticate yourself through smtp you have to download a phpmailer? Quote Link to comment https://forums.phpfreaks.com/topic/115231-mail-function/#findComment-592508 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.