I've been using this script for the last couple months with no problems. It would generate an email within seconds every time. About a week ago, for reasons I have not be able to discover, it stopped sending the emails.
I'm hoping someone here can shed some light on what's wrong.
Here is my HTML:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
ul, li, p, body {
margin: 0;
padding: 0;
}
body {
color: #333;
background: url(images/bkgGradient.jpg) repeat-x #fff4a0;
font-family: arial, helvetica, sans-serif;
font-size: 12px;
}
.error_strings {
font-size: 12px;
color: #900;
margin: 2px 0px 12px;
}
.error_strings ul {
list-style-type: none;
}
.formLeft {
width: 105px;
font-size: 12px;
font-weight: bold;
margin-top: 6px;
float: left;
}
.formRight {
width: 335px;
font-size: 12px;
margin-top: 3px;
float: left;
}
</style>
<script language="javascript" type="text/javascript" src="gen_validatorv5.js"></script>
</head>
<body>
<form name="request" id="request" method="post" action="thank-you.php">
<div style="width: 440px">
<div class="formLeft">Name:</div>
<div class="formRight"><input type="text" name="name" id="name" style="width: 320px" /></div>
<div class="formLeft">Address:</div>
<div class="formRight"><input type="text" name="address" id="address" style="width: 320px" /></div>
<div class="formLeft">City:</div>
<div class="formRight"><input type="text" name="city" id="city" style="width: 320px" /></div>
<div class="formLeft">State:</div>
<div class="formRight"><input type="text" name="state" id="state" style="width: 320px" /></div>
<div class="formLeft">Zip:</div>
<div class="formRight"><input type="text" name="zip" id="zip" style="width: 320px" /></div>
<div class="formLeft">Email:</div>
<div class="formRight"><input type="text" name="email" id="email" style="width: 320px" /></div>
<div class="formLeft">Phone:</div>
<div class="formRight"><input type="text" name="phone" id="phone" style="width: 320px" /></div>
<div class="formLeft">Best Time to Call:</div>
<div class="formRight"><input type="text" name="best" id="best" style="width: 320px" /></div>
<div class="formLeft">Brief Description of Job:</div>
<div class="formRight"><textarea name="description" id="description" cols="1" rows="5" style="width: 320px"></textarea></div>
</div>
<div style="clear: both"></div>
<input type="submit" value="Submit" name="submit" style="margin: 6px 0 10px 367px" />
</form>
<div id="request_errorloc" class="error_strings" style="height: 80px; margin-left: 105px"></div>
<script language="JavaScript" type="text/javascript">
var frmvalidator = new Validator("request");
frmvalidator.EnableOnPageErrorDisplaySingleBox();
frmvalidator.EnableMsgsTogether();
frmvalidator.addValidation("name","req","Please enter your first name");
frmvalidator.addValidation("email","req","Please enter an email address");
frmvalidator.addValidation("email","email","Please enter a valid email address");
frmvalidator.addValidation("phone","req","Please enter your phone number");
frmvalidator.addValidation("best","req","Please enter the best time for us to call");
frmvalidator.addValidation("description","req","Please enter a brief description of the job");
</script>
</body>
</html>
and here is the PHP I'm using:
Code:
<?php
// -------------------- EMAIL CONFIGURATION ---------------------
$mailto = 'smarshall@stltoday.com' ;
$subject = "Feedback Form Test" ;
$thankyouurl = "http://dmsgroup.co/templates/thank-you.html" ; // <----- THIS LINE CANE BE REMOVED IF HTML FOLLOWS THE PHP
// -------------------- END OF EMAIL CONFIGURATION ---------------
// -------------------- FORM FIELDS ---------------------
$name = $_POST['name'] ;
$address = $_POST['address'] ;
$city = $_POST['city'] ;
$state = $_POST['state'] ;
$zip = $_POST['zip'] ;
$email = $_POST['email'] ;
$phone = $_POST['phone'] ;
$best = $_POST['best'] ;
$description = $_POST['description'] ;
// -------------------- END OF FORM FIELDS ---------------------
// ----- DON'T CHANGE ANYTHING IN THE SECTION BELOW EXCEPT THE NAME OF THE EMAIL FIELD (IF NECESSARY)
$headersep = $uself ? "\n" : "\r\n" ;
$nl = "<br />";
$http_referrer = getenv( "HTTP_REFERER" );
$headers = "From: \"$name\" <$email>" . $headersep ; // ----- THE NAME OF THE EMAIL FIELD MUST MATCH HERE ***
$headers .= "Reply-To: \"$name\" <$email>" . $headersep ; // ----- THE NAME OF THE EMAIL FIELD MUST MATCH HERE ***
$headers .= "X-Mailer: chfeedback.php 2.16.2" . $headersep ;
$headers .= "MIME-Version: 1.0" . $headersep ;
$headers .= 'Content-Type: text/html; charset="iso-8859-1"' ;
// ----- DON'T CHANGE ANYTHING IN THE SECTION ABOVE EXCEPT THE NAME OF THE EMAIL FIELD (IF NECESSARY)
// ----- THIS IS WHERE THE EMAIL BODY IS CREATED
$body = "<span style='font-family: Verdana, sans-serif; font-size: 12px; line-height: 16px'>
<b>Sent from:</b> $http_referrer by $name (" . "$email" . ")" . // ----- THE NAME OF THE EMAIL FIELD MUST MATCH HERE ***
$nl . $nl .
"<b>Name:</b> " . $name . $nl .
"<b>Address:</b> " . $address . $nl .
"<b>City:</b> " . $city . $nl .
"<b>State:</b> " . $state . $nl .
"<b>Zip:</b> " . $zip . $nl .
"<b>Email:</b> " . $email . $nl .
"<b>Phone:</b> " . $phone . $nl .
"<b>Best time to call:</b> " . $best . $nl .
"<b>Brief description of job:</b> " . $description . $nl . "</span>" ;
mail($mailto, $subject, $body, $headers );
// ----- THE NEXT TWO LINES CAN BE REMOVED IF HTML FOR A THANK YOU PAGE FOLLOWS THE PHP
header( "Location: $thankyouurl" );
exit ;
?>
No blank linkes before the <?php . The reason for this is leaving a blank line will output headers which could affect your script.
Posftix is an email program which runs on linux which most shared hosts use for sending email, looking at this would tell you if the email was sent, or what reason it wasn't sent.
Do you have access to the apache error log? You might find some useful information on there too.
No blank linkes before the <?php . The reason for this is leaving a blank line will output headers which could affect your script.
There are no blank lines before the <?php.
Originally Posted by Alan01252
Posftix is an email program which runs on linux which most shared hosts use for sending email, looking at this would tell you if the email was sent, or what reason it wasn't sent.
Do you have access to the apache error log? You might find some useful information on there too.
I'm gonna check with our admin on this. I have no idea on either of these.
no the mail function will still execute the $send variable will just be assigned the return value of that function. In this case (assuming your emails still aren't being sent) $send will be (boolean) false.
I got an older script from our admin. Emails are working now, altho, I'm not sure what the problem was.
Right now, I'm going thru the old script and gradually updating it with parts of the new code.
Here's what I've got so far:
Code:
<?PHP putenv("TZ=US/Central"); $time = date("M j, Y, g:i a");
if($_SERVER['REQUEST_METHOD'] == "POST")
{
$name = $_POST["name"];
$email = $_POST["email"];
$comments = $_POST["comments"];
$recipient = "smarshall@stltoday.com";
$subject = "testing email form";
// ----- THIS IS WHERE THE EMAIL BODY IS CREATED
$headersep = $uself ? "\n" : "\r\n" ;
$nl = "<br />";
$body = "<span style='font-family: Verdana, sans-serif; font-size: 12px; line-height: 16px'>
<b>Sent from:</b> $http_referrer by $name (" . "$email" . ")" . // ----- THE NAME OF THE EMAIL FIELD MUST MATCH HERE ***
$nl . $nl .
"<b>Name:</b> " . $name . $nl .
"<b>Email:</b> " . $email . $nl .
"<b>Comments:</b> " . $comments . $nl . "</span>" ;
//$body = "<p><b>Name:</b> $name<p><b>Email:</b> $email<p><b>Questions or comments:</b> $comments";
// ----- DON'T CHANGE ANYTHING IN THE SECTION BELOW EXCEPT THE NAME OF THE EMAIL FIELD (IF NECESSARY)
//$headersep = $uself ? "\n" : "\r\n" ;
//$nl = "<br />";
$http_referrer = getenv( "HTTP_REFERER" );
$headers = "From: \"$name\" <$email>" . $headersep ; // ----- THE NAME OF THE EMAIL FIELD MUST MATCH HERE ***
$headers .= "Reply-To: \"$name\" <$email>" . $headersep ; // ----- THE NAME OF THE EMAIL FIELD MUST MATCH HERE ***
$headers .= "X-Mailer: chfeedback.php 2.16.2" . $headersep ;
$headers .= "MIME-Version: 1.0" . $headersep ;
$headers .= 'Content-Type: text/html; charset="iso-8859-1"' ;
// ----- DON'T CHANGE ANYTHING IN THE SECTION ABOVE EXCEPT THE NAME OF THE EMAIL FIELD (IF NECESSARY)
$send = mail($recipient,$subject,$body,$headers);
header( "Location: thank-you.php" ) ;
}
else
{
echo '<p><a href="catering.html">Please fill in the form</a></p>';
}
?>
I've determined that the HTTP_REFERER variable is what's been causing the emails to not send. If I remove all instances of HTTP_REFERER, the email sends in a matter of seconds.
If you comment out the sending stuff and just echo out $http_referrer what do you get? I'm guessing there's some special character in there which is causing this to fail.
To prove this I guess you could do $http_referrer = htmlspecialchars(getenv( "HTTP_REFERER" ));
Bookmarks