...

View Full Version : "Simple Contact Form" PHP not sending email



Gabby7
09-02-2009, 08:46 PM
Hello+
I have attempted to write a simple PHP script to send the contact information to a specific email address. Everything seems to be working fine, except the email is not reaching me. I'm not certain what is going wrong - can anyone help? The PHP code is below:


<?php

/* subject and email variables */

$emailSubject = 'Contact From Website!';
$webMaster = 'nomad654321@earthlink.net';

/* gathering data variables */

$emailField = $_POST['email'];
$nameField = $_POST['cname'];
$phoneField = $_POST['phone'];
$interestedField = $_POST['interested'];
$artworkField = $_POST['artwork'];
$commentsField = $_POST['comments'];

$body = <<<EOD
<br><hr><br>
Email: $email <br>
Name: $cname <br>
Phone Number: $phone <br>
Interested in: $interested <br>
Artwork: $artwork <br>
Comments: $comments <br>
EOD;

$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
$success = mail($webMaster, $emailSubject, $body, $headers);

/* results rendered as HTML */

$theResults = <<<EOD
<html>
<head>
<title>Photography by Lynn Santus</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
body {
font-family: "Times New Roman", Times, serif;
font-size: 18px;
font-style: normal;
line-height: normal;
font-weight: normal;
color: #330099;
text-decoration: none;
background-image: url(images/greengrunge10.png);
text-align: center;
}
-->
</style>
</head>

<div>
<div align="center">
<p><img src="images/lynnbanner.png" alt="Photography by Lynn Santus" width="801" height="150" border="0" usemap="#Map">
<map name="Map"><area shape="rect" coords="84,3,603,154" href="index.html" alt="Link to Home Page">
</map></p>
<p>Thank you for your interest! Your email will be answered very soon!</p>
<p>Click <a href="index.html">here</a> to return to the Home Page. </p>
</div>
</div>
</body>
</html>
EOD;
echo "$theResults";

?>

Thank you for any guidance offered...

Fumigator
09-02-2009, 08:51 PM
Two things-- Turn on full error reporting:



error_reporting(E_ALL);
ini_set("display_errors", 1);


And check the success of the mail() function-- you assign the result to variable $success but then you don't check it.



if (!$success) {
die("error sending email!");
}


If the mail() function fails check your PHP error log.

If all of that doesn't get you anywhere, tell us what kind of PHP install you are using and dump the contents of your phpinfo() here.

_Aerospace_Eng_
09-02-2009, 09:03 PM
I also suggest removing your actual email address from your post or you will soon start to get spammed.

ajetrumpet
09-02-2009, 09:19 PM
And check the success of the mail() function-- you assign the result to variable $success but then you don't check it.



if (!$success) {
die("error sending email!");
}


If the mail() function fails check your PHP error log.you may also want to use your own logs. i do for my website. when i do batch mailings, i write the results to a log then check it when i'm done to see if anything failed in case i need to resend some. it might be of use to you.
if (!$success) {
$logline = "delivery failed...|\r\n"; }
else { $logline = "delivery successful!|\r\n"; }

$file = @fopen("mylogfile", "a");
fputs($file, $logline );
fclose($file);

Gabby7
09-02-2009, 10:10 PM
Thank you, everyone! I will do as you suggest and if it doesn't work, then I will re-post. Thank you.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum