Forum Moderators: coopster
I'm having some trouble with a php contact form on my site. It is based around a basic contact.php form which POSTS and redirects to a sendemail.php form with the variables. As a result, the webmaster receives 2 emails: 1 correct submission and 1 blank email from "Apache".
Here's some code snippetts. Any suggestions hugely appreciated! Cheers - p
-- CONTACT.PHP --
<FORM action="sendemail.php" METHOD="POST">
<?php
$ipi = getenv("REMOTE_ADDR");
$httprefi = getenv ("HTTP_REFERER");
$httpagenti = getenv ("HTTP_USER_AGENT");
?>
<input type=hidden name="ip" value="<?php echo $ipi?>">
<input type=hidden name="httpref" value="<?php echo $httprefi?>">
<input type=hidden name="httpagent" value="<?php echo $httpagenti?>">
Your Name<br>
<input name="name" type="text" class="text">
<br>Your Email<br>
<input type="text" name="email" class="text">
<br>Subject<br>
<input type="text" name="subject" class="text">
<br>Comment<br>
<textarea name="notes" cols="30" rows="6" wrap="VIRTUAL" id="comment" class="text"></textarea>
<br><br><input type="submit" name="submit" value="-send-" class="buttons"><br>
</form>
--SENDEMAIL.PHP--
<?php
$myemail = "WEBMASTER@EXAMPLE.COM";
if(!$email == "" && (!strstr($email,"@") ¦¦!strstr($email,".")))
{
echo "<a href='javascript:history.back();'>Go Back</a> and enter valid e-mail";
$badinput = "<br>Feedback was NOT submitted";
}
if(empty($name) ¦¦ empty($email) ¦¦ empty($notes )) {
echo "<a href='javascript:history.back();'>Go Back</a> - fill in all fields";
}
$todayis = date("l, F j, Y, g:i a") ;
$notes = stripcslashes($notes);
$notes = "Somebody has sent you an email from the website.\n
$notes \n
From: $name ($email)\n \n
Additional Info : IP = $ip \n
Browser Info: $httpagent \n
Referral : $httpref \n
Message sent at $todayis [GMT]
";
$from = "From: $email\r\n";
if ($myemail!= "")
mail($myemail, $subject, $notes, $from);
?>
THANKS AGAIN!
First thing I'd try is using \n at the end of the from part of the header.
$from = "From: $email\r\n";
to
$from = "From: $email\n";
It may not matter put some mail program are finickity about \r\n and \n
If that does nothing then I'd start doing some process of elimination by putting strings right in the mail funtion.
mail("me@example.com", "test", "test", "From: Me Myself <me@example.com>");
If that works then try to figure out which variable is causing the grief.
<?php
$myemail = "user@example.com";
if(!$_POST['email'] == "" && (!strstr($email,"@") ¦¦!strstr($email,".")))
{
echo "<a href='javascript:history.back();'>Go Back</a> and enter valid e-mail";
$badinput = "<br>Feedback was NOT submitted";
}
if(empty($name) ¦¦ empty($email) ¦¦ empty($notes )) {
echo "<a href='javascript:history.back();'>Go Back</a> - fill in all fields";
}
$todayis = date("l, F j, Y, g:i a") ;
$notes = stripcslashes($notes);
$notes = "Somebody has sent you an email from the icarus website.\n
$notes \n
From: $name ($email)\n \n
Additional Info : IP = $ip \n
Browser Info: $httpagent \n
Referral : $httpref \n
Message sent at $todayis [GMT]
";
$from = "From: $email\n";
if ($myemail!= "")
mail($myemail, $subject, $notes, $from);
?>
thanks in advance for any further help!
p
Then start using the mail function again, if you have access to mail logs that would help as well, as it may give you more information. Also, take a look at the headers on the email you receive as that also may show you that a header or 2 is messed up.
also
$notes = stripcslashes($notes);
$notes = "Somebody has sent you an email from the icarus website.\n
the second line overwrites the content of the notes var. I think you may have wanted to use .=
For instance:
$name becomes $_POST['name']
$notes becomes $_POST['notes']
Any field from the form you are referencing should be referenced with $_POST, unless global vars are on (which is a very bad thing, and your script may break on servers that have global vars off).
Hope this helps!