Jump to content

Recommended Posts

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

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);

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.

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.)

 

 

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! :-)

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.