Why Won't My PHP send mail?
Posted: Sat Apr 24, 2010 2:18 am
Can anyone tell me why this script won't send emails?
?php
// Must include botblock.inc
require "botblock.inc";
// Insert any HTML header or PHP code
// echo "<h2>Chime Bot Block</h2>";
// echo "<h3>Demo Form</h3>";
if(validBotBlock())
{
// Codeword is correct.
// Write your own code to process the form.
// For example:
echo "Yup! Codeword was correct
";
$mailto = 'abrogard@yahoo.com' ;
$subject = "XYFord Feedback Form" ;
$formurl = "feedbackform.php" ;
$homepage = "index.html" ;
$errorurl = "error.html" ;
$thankyouurl = "thankyou.html" ;
$uself = 0;
$headersep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" : "\n" ;
$username = $_POST['username'] ;
$firstname = $_POST['firstname'] ;
$email = $_POST['email'] ;
$comments = $_POST['comments'] ;
$secondname = $_POST['secondname'] ;
$country = $_POST['country'] ;
$phone = $_POST['phone'] ;
// do write to database now---------------------------
$link = mysql_connect("localhost", "xxxxxx", "yyyyyy") or die("Could not connect : " . mysql_error());
$DB = "xyfordco";
$table = "clients";
mysql_select_db($DB) or die ("Database $DB not select.." . mysql_error());
$query = "INSERT INTO $table(username,firstname,secondname,email,country,phone,comments) values('$username','$firstname','$secondname','$email','$country','$phone','$comments')";
if ( ! mysql_query( $query, $link) )
die ( "MySQL error.....<p>" .mysql_error() );
$http_referrer = getenv( "HTTP_REFERER" );
if (!isset($_POST['email'])) {
header( "Location: $formurl" );
exit ;
}
if ( ereg( "[\r\n]", $username ) || ereg( "[\r\n]", $email ) ) {
header( "Location: $errorurl" );
exit ;
}
if (get_magic_quotes_gpc()) {
$comments = stripslashes( $comments );
}
$messageproper =
"This message was sent from:\n" .
"$http_referrer\n" .
"------------------------------------------------------------\n" .
"UserName of sender: $username\n" .
"Firstname of sender: $firstname\n" .
"Secondname of sender : $secondname\n" .
"Country of sender : $country\n" .
"Phone number of sender: $phone\n" .
"Email of sender: $email\n" .
"------------------------- COMMENTS -------------------------\n\n" .
$comments .
"\n\n------------------------------------------------------------\n" ;
mail($mailto, $subject, $messageproper,
"From: \"$username\" <$email>" . $headersep . "Reply-To: \"$username\" <$email>" . $headersep . "X-Mailer: chfeedback.php 2.07" );
header( "Location: $thankyouurl" );
// exit ;
exit ;
}
else
{
$homepage = "index.html";
// Codeword is incorrect.
// Show some error or go back to last page.
// For example:
echo "Bad monkey! Wrong codeword.";
header( "Location: $homepage" );
exit;
}
?>
?php
// Must include botblock.inc
require "botblock.inc";
// Insert any HTML header or PHP code
// echo "<h2>Chime Bot Block</h2>";
// echo "<h3>Demo Form</h3>";
if(validBotBlock())
{
// Codeword is correct.
// Write your own code to process the form.
// For example:
echo "Yup! Codeword was correct
$mailto = 'abrogard@yahoo.com' ;
$subject = "XYFord Feedback Form" ;
$formurl = "feedbackform.php" ;
$homepage = "index.html" ;
$errorurl = "error.html" ;
$thankyouurl = "thankyou.html" ;
$uself = 0;
$headersep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" : "\n" ;
$username = $_POST['username'] ;
$firstname = $_POST['firstname'] ;
$email = $_POST['email'] ;
$comments = $_POST['comments'] ;
$secondname = $_POST['secondname'] ;
$country = $_POST['country'] ;
$phone = $_POST['phone'] ;
// do write to database now---------------------------
$link = mysql_connect("localhost", "xxxxxx", "yyyyyy") or die("Could not connect : " . mysql_error());
$DB = "xyfordco";
$table = "clients";
mysql_select_db($DB) or die ("Database $DB not select.." . mysql_error());
$query = "INSERT INTO $table(username,firstname,secondname,email,country,phone,comments) values('$username','$firstname','$secondname','$email','$country','$phone','$comments')";
if ( ! mysql_query( $query, $link) )
die ( "MySQL error.....<p>" .mysql_error() );
$http_referrer = getenv( "HTTP_REFERER" );
if (!isset($_POST['email'])) {
header( "Location: $formurl" );
exit ;
}
if ( ereg( "[\r\n]", $username ) || ereg( "[\r\n]", $email ) ) {
header( "Location: $errorurl" );
exit ;
}
if (get_magic_quotes_gpc()) {
$comments = stripslashes( $comments );
}
$messageproper =
"This message was sent from:\n" .
"$http_referrer\n" .
"------------------------------------------------------------\n" .
"UserName of sender: $username\n" .
"Firstname of sender: $firstname\n" .
"Secondname of sender : $secondname\n" .
"Country of sender : $country\n" .
"Phone number of sender: $phone\n" .
"Email of sender: $email\n" .
"------------------------- COMMENTS -------------------------\n\n" .
$comments .
"\n\n------------------------------------------------------------\n" ;
mail($mailto, $subject, $messageproper,
"From: \"$username\" <$email>" . $headersep . "Reply-To: \"$username\" <$email>" . $headersep . "X-Mailer: chfeedback.php 2.07" );
header( "Location: $thankyouurl" );
// exit ;
exit ;
}
else
{
$homepage = "index.html";
// Codeword is incorrect.
// Show some error or go back to last page.
// For example:
echo "Bad monkey! Wrong codeword.";
header( "Location: $homepage" );
exit;
}
?>