7

I have a small script which im using to test PHP mail(), as below:

<?php
error_reporting(E_ALL);
ini_set("display_errors",1);

mail('x@x.com','test','test') or die('could not send') ;

echo "Mail Sent";

?>

When I run this script I get no output at all. I don't get an error, I dont get anything echoed, I view the source, nothing.

Ive tried so many different variations, if I take out the mail function in the code above it will work fine.

This is a Windows hosted server so I have not access to php.ini or anything

Could it be some configuration that is causing no output when its encountering an error?

a_m0d
  • 12,034
  • 15
  • 57
  • 79
Tim
  • 2,667
  • 4
  • 32
  • 39
  • PS I know that the mail() function will probably error if sendmail_from isnt set or not given in the header im just trying to understand why the errors wont output – Tim Mar 11 '10 at 00:52
  • Well, your `mail` call contains a syntax error (`'test,` should have an extra apostrophe). That could be the reason for the program dying ... PHP should tell you that, though, which is probably the point of this question. – cmptrgeekken Mar 11 '10 at 01:00

2 Answers2

17

According to the PHP Runtime Configuration guide:

Note: Although display_errors may be set at runtime (with ini_set()), it won't have any affect if the script has fatal errors. This is because the desired runtime action does not get executed.

Your code appears to have a syntax error ('test, is missing a closing apostrophe). Thus, your program is encountering a fatal error. The only way to get a fatal error to display (EDIT: outside the error log) is to set display_errors = 1 in your php.ini file.

cmptrgeekken
  • 8,052
  • 3
  • 29
  • 35
1

The problem is with your sendmail server configuration. If youre testing this script on your personal development environment, don't worry about it. It can be a pita to setup/configure a sendmail server. If you're having this problem on your production server, the simpliest solution is to use a mailer library that has an smtp option (allowi g your email to be sent to an external smtp server for processing/delivery).

Here is a guide on using a 3rd party smtp mail script... http://email.about.com/od/emailprogrammingtips/qt/PHP_Email_SMTP_Authentication.htm

John Himmelman
  • 21,504
  • 22
  • 65
  • 80