Page 1 of 1

PHP 5 Mail issues.

Posted: Tue Dec 27, 2011 10:52 am
by ndjustin20
Hello Everyone,

I'm having issues sending mail using a simple PHP mail script. The script generates no errors and from what I can tell should be sending the email. Here is the phpinfo link http://www.abesfamilyfire.com/phpinfo.php CentOS Linux and Apache

Here is the form

Code: Select all


<form  onsubmit="return checkFormData()" id="contactForm" action="contactProcess.php" method="get">
	<div style="background-color:#FFFF66">
   <label for="name">Name:</label>
   <input type="text" name="name" id="name" size="20" maxlength="30" /><br /><br />
   
   <label for="address">Address:</label>
   <input type="text" name="address" id="address" size="20" maxlength="70"  /><br /><br />
   
   <label for="city">City:</label>
   <input type="text" name="city" id="city" size="20" maxlength="70" /><br /><br />
   
   <label for="state">State:</label>
   <input type="text" name="state" id="state" size="20" maxlength="70" /><br /><br />
   
   <label for="zipCode">Zip Code:</label>
   <input type="text" name="zipCode" id="zipCode" size="20" maxlength="70" /><br /><br />
   
   <label for="email">Email:</label>
   <input type="text" name="email" id="email" size="20" maxlength="70" /><br /><br />

   <label for="message">Include A Message:</label>
   <textarea rows="10" cols="40" name="message" id="message" size="20" maxlength="500"></textarea><br /><br />
   
   <INPUT TYPE="image" SRC="SendYourMessage.jpg" BORDER="0" ALT="Send Your Message"><br /><br />
   
   </div>
   </form>






Here is the processing code of the script

Code: Select all


<?php

$Name = $_GET['name'];
$email = $_GET['email'];
$recipient = "ndjustin20@hotmail.com";
$mail_body = $_GET['name'] . "\r\n" . $_GET['address'] . "\r\n" . $_GET['city'] . "\r\n" . 
$_GET['state'] . "\r\n" . $_GET['zipCode'] . "\r\n" . "\r\n" . "\r\n" . $_GET['message'];
$subject = "Feedback from Abes Family Fire Website";


$header = "From: ". $Name . " <" . $email . ">\r\n"; //optional headerfields

ini_set('sendmail_from', 'abe@abesfamilyfire.com'); //Suggested by "Some Guy"

mail($recipient, $subject, $mail_body); //mail command :)
?>

<?php $pageNum = 7 ?>

<?php include('messages.php'); ?>
<?php include('head.php'); ?>


<body class="thrColHybHdr">


<div id="container">
  <div id="header">
    <h1 align="center"><?php echo $headerMessage; ?></h1>
    <!-- end #header --></div>
  <?php include('sideBar1.php'); ?>
  <?php include('sideBar2.php'); ?>
  <?php include('main.php'); ?>
  <?php include('footer.php'); ?>

Any help is much appreciated.

Re: PHP 5 Mail issues.

Posted: Tue Dec 27, 2011 12:22 pm
by s.dot
I know mail() must have a from parameter. Add $header as the last parameter in your mail() argument.
Is your error reporting on?

Code: Select all

ini_set('display_errors', 'On');
error_reporting(E_ALL);

Re: PHP 5 Mail issues.

Posted: Tue Dec 27, 2011 12:53 pm
by califdon
You are making your task much more difficult than it needs to be. First of all, there's no need to enclose each and every PHP line in <?php ... ?> tags. For example, instead of the final 4 lines above, just code it this way:

Code: Select all

<?php
include('sideBar1.php');
include('sideBar2.php');
include('main.php');
include('footer.php');
?>
Next, I would recommend using the POST method of sending the form data, rather than the GET method. There are many reasons for this, including security, appearance of the URL, etc. See http://www.tizag.com/phpT/postget.php

Then, since you are experiencing a problem and would like to see the error message, if any, you can do several things on a temporary basis, while you are debugging the script, and these should later be removed before going public with the final version:

1. In order to display error messages, insert the following PHP commands immediately after the first <?php line of your script:

Code: Select all

error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);
2. Change your mail() function line to this:

Code: Select all

mail($recipient, $subject, $mail_body) or die("Error Sending Mail");
This will halt execution of your script and print the message if there is an error returned by the mail() function.

Re: PHP 5 Mail issues.

Posted: Tue Dec 27, 2011 2:52 pm
by ndjustin20
Ok so here is the code. There are 0 errors reporting and I can see the values in the GET function. I have no idea why it's not sending at this point. Is there something in the ini file I need to change????

Code: Select all


$Name = $_GET['name'];
$email = $_GET['email'];
$recipient = "ndjustin20@hotmail.com";
$mail_body = $_GET['name'] . "\r\n" . $_GET['address'] . "\r\n" . $_GET['city'] . "\r\n" . 
$_GET['state'] . "\r\n" . $_GET['zipCode'] . "\r\n" . "\r\n" . "\r\n" . $_GET['message'];
$subject = "Feedback from Abes Family Fire Website";


$header = "From: ". $Name . " <" . $email . ">\r\n"; //optional headerfields

ini_set('sendmail_from', 'abe@abesfamilyfire.com'); //Suggested by "Some Guy"

mail($recipient, $subject, $mail_body) or die("Error Sending Mail"); //mail command :)

print_r($_GET);

ini_set('display_errors', 'On');
 	error_reporting(E_ALL);


Re: PHP 5 Mail issues.

Posted: Tue Dec 27, 2011 3:13 pm
by Celauran
There's also the possibility that it's not a PHP error. Have you checked that sendmail is properly configured? Any clues in your sendmail logs?

Re: PHP 5 Mail issues.

Posted: Tue Dec 27, 2011 3:15 pm
by ndjustin20
How do I check my sendmail log or ensure it is configured properly?

Re: PHP 5 Mail issues.

Posted: Tue Dec 27, 2011 3:21 pm
by Celauran
If it's not your machine, just disregard that.

Re: PHP 5 Mail issues.

Posted: Tue Dec 27, 2011 3:24 pm
by ndjustin20
It's a dedicated server so I have access to all portions of it.

Re: PHP 5 Mail issues.

Posted: Tue Dec 27, 2011 3:49 pm
by Celauran
My CentOS machines have the mail log at /var/log/maillog.

Also, I tested your code on my test machine and received the email, so the problem definitely isn't your code.