stuartsparks Posted April 8, 2010 Share Posted April 8, 2010 Hi, Apologies if this has been asked/answered before, but after much googling and looking through here, i believe i have done this right. But it's not working. I'm new to PHP and am using the Head First book to learn and i'm stuck with sending emails. I'm running PHP 5 on IIs 7 on Windows Server 2008 R2. The php.ini is set up as follows: [mail function] ; For Win32 only. SMTP = sparks-net.co.uk smtp_port = 25 [email protected] auth_password=**** My (basic) PHP script is currently has the command:- mail($emailto, $subject, $msg, 'From:[email protected]'); Obviously the 3 variables are defined and contain valid data. But when the form is submitted on explorer, i just get the "500 - Internal server error" page. If i remove this mail() line of code, then all works fine! Please help, as i don't know what's going wrong, and can't find any log files to help point me in the right direction! Many Thanks Stu Quote Link to comment https://forums.phpfreaks.com/topic/198036-using-php-mail-command-on-own-pop-email-server/ Share on other sites More sharing options...
PFMaBiSmAd Posted April 8, 2010 Share Posted April 8, 2010 For debugging purposes (remove them when you are done), add the following two lines of code after your first opening <?php tag to get php to display all the errors it detects - ini_set("display_errors", "1"); error_reporting(E_ALL); Quote Link to comment https://forums.phpfreaks.com/topic/198036-using-php-mail-command-on-own-pop-email-server/#findComment-1039123 Share on other sites More sharing options...
stuartsparks Posted April 8, 2010 Author Share Posted April 8, 2010 Hi and thanks for the quick reply! I've added those 2 lines of code. But i'm still just getting: 500 - Internal server error. There is a problem with the resource you are looking for on Stus Server, and it cannot be displayed. The full code is (don't laugh!): <html> <head> <title>Stus Test PHP Results Screen</title> </head> <body> <h2>Displaying Text You input from the previous screen</h2> <?php ini_set("display_errors", "1"); error_reporting(E_ALL); $first_name = $_POST['YourFirstName']; $isstugreat = $_POST['isstugreat']; $emailto = '[email protected]'; $subject = 'phptestemail'; echo '<br />'; echo '<br />'; echo 'Thanks for trying this form.<br />'; echo '<br />'; echo 'Your First Name is ' . $first_name; echo '<br />'; echo 'Your Surname is ' . $_POST['YourSurName']; echo '<br />'; echo 'Is Stu Great - ' . $isstugreat; $msg = 'The users firstname is ' . $first_name . ' and the surname is ' . $_POST['YourSurName'] . ' and in response to is Stu Great they answer - ' . $isstugreat; echo '<br />'; echo '<br />'; echo $msg mail($emailto, $subject, $msg, 'From:[email protected]'); echo 'Email Sent'; ?> </body> </html> Thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/198036-using-php-mail-command-on-own-pop-email-server/#findComment-1039124 Share on other sites More sharing options...
PFMaBiSmAd Posted April 8, 2010 Share Posted April 8, 2010 Line 24 is missing the semi-colon ; and your code is producing a fatal parse error. To see fatal parse errors when developing and debugging code (to save a lot of time), you must set the error_reporting/display_errors settings in your master php.ini (when you have access to it) or in a local php.ini (when php is running as a CGI application.) Quote Link to comment https://forums.phpfreaks.com/topic/198036-using-php-mail-command-on-own-pop-email-server/#findComment-1039127 Share on other sites More sharing options...
stuartsparks Posted April 8, 2010 Author Share Posted April 8, 2010 It works! Wahoo! Thanks so much! Can't believe that's all it was. Is this the bit i need to change in php.ini : ; - error_reporting = E_ALL ; By default, PHP suppresses errors of type E_NOTICE. These error messages ; are emitted for non-critical errors, but that could be a symptom of a bigger ; problem. Most notably, this will cause error messages about the use ; of uninitialized variables to be displayed. Shall i make it just: error_reporting = E_ALL (removing the colon) Thanks again for your help, now i can move onto the mySQL chapter! :-) Quote Link to comment https://forums.phpfreaks.com/topic/198036-using-php-mail-command-on-own-pop-email-server/#findComment-1039132 Share on other sites More sharing options...
PFMaBiSmAd Posted April 8, 2010 Share Posted April 8, 2010 Also - display_errors = on You will need to stop and start the IIS service (in the service control panel) to get any changes made to the master php.ini to take effect. Also, use a phpinfo() statement to confirm that the settings were actually changed. Quote Link to comment https://forums.phpfreaks.com/topic/198036-using-php-mail-command-on-own-pop-email-server/#findComment-1039136 Share on other sites More sharing options...
stuartsparks Posted April 8, 2010 Author Share Posted April 8, 2010 Excellent. Thankyou Quote Link to comment https://forums.phpfreaks.com/topic/198036-using-php-mail-command-on-own-pop-email-server/#findComment-1039140 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.