RSS RSS feed | Atom Atom feed

Problems with PHP mail()

Tips on working with PHP mail()

The Problem.

On some servers the mail() function does not seem to work or works intermittently. Following are some diagnostic tips and solutions that we have found useful on a Linux webserver.

 The Solution Areas

The solutions seem to be related to addressing one or more of the following issues

  1. Incorrectly configured PHP - see php.ini if available.
  2. Incorrect syntax or missing headers for email
  3. On Linux - Sendmail not configured correctly or is not running.

Testing

Before getting started on fixing the problem, it is good to have a simple "test" to use as you try different solutions. Create the following PHP file:

<?php
$recipient = "name@yourdomain.com";
$subject = "Test from PHP";
$message = "Testing mail body";
mail("$recipient","$subject","$message");
?>

< html>< head>< title>< /title>< /head>
< body>
Testing mail via PHP< br>< br>
recipient: < ?php echo "$recipient"; ?>< br>
subject: < ?php echo "$subject"; ?>< br>
message: < ?php echo "$message"; ?>< br>
< /body>< /html>

 

 Incorrectly Configured PHP

You may not have access to the php.ini file that controls the configuration of PHP on your webserver.  It check your settings on your install create a small php file that has:

<?php
phpInfo()
?>

If see a problem and you do not have access to this file you may need to contact your webserver provider and discuss these settings. 

The php.ini file is found in different places depending on the way PHP was compiled on that machine AND how Apache is installed . The most common areas are:

../apache/php/php.ini
../apache/php/lib/php.ini

 

 




Add a comment Send a TrackBack