problem with contact form send mail function

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gman1234
Forum Newbie
Posts: 3
Joined: Wed Sep 15, 2010 6:21 am

problem with contact form send mail function

Post by gman1234 »

Hi
I have this form, when I want to send mail to myself with all the fields form the form, no matter what I do I can not get it to work. its ok sending reply email to the person tho. Area of problem highlighted in bold.

Please help
Gren

See code:

Code: Select all

// load the variables form address bar
include("my_message.php");
$name = $_POST["name"];
$subject = $_POST["subject"];
$message = $_POST["message"];
$number = $_POST["number"];
$from = $_POST["from"];
$verif_box = $_POST["verif_box"];

// remove the backslashes that normally appears when entering " or '
$name = stripslashes(name);
$message = stripslashes($message); 
$subject = stripslashes($subject); 
$number= stripslashes ($number);
$from = stripslashes($from); 
//auto reply vars
//$replysub="the food galley";
$replymsg="Thanks for contacting the food galley, we will be intouch soon.\n\n the food gallery";
$email="grenambrose@gmail.com";
// check to see if verificaton code was correct
if(md5($verif_box).'a4xn' == $_COOKIE['tntcon']){
	// if verification code was correct send the message and show this page
[b]	mail("grenambrose@gmail.com", 'Online Form: '.$subject, $_SERVER['REMOTE_ADDR']."\n\n".$message, "From: $from");[/b]
	mail($from, 'the food galley',$mymessage, $headers);
	// delete the cookie so it cannot sent again by refreshing this page
	setcookie('tntcon','');
} else if(isset($message) and $message!=""){
	// if verification code was incorrect then return to contact page and show error
	header("Location: index.php?subject=$subject&from=$from&message=$message&wrong_code=true");
	exit;
} else {
	echo "no variables received, this page cannot be accessed directly";
	exit;
	}
?>
<!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=iso-8859-1" />
<title>E-Mail Sent</title>
<style type="text/css">
<!--
body,td,th {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 12px;
}
-->
</style></head>

<body>
Email sent. Thank you.
</body>
</html>
Last edited by gman1234 on Thu Sep 16, 2010 7:40 am, edited 1 time in total.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: problem with contact form send mail function

Post by Jonah Bron »

What doesn't work? Do you get an error, or does the email just not send? Please surround your code with [syntax=php][/syntax] tags when posting code.
gman1234
Forum Newbie
Posts: 3
Joined: Wed Sep 15, 2010 6:21 am

Re: problem with contact form send mail function

Post by gman1234 »

hi
when i add more variables ie $ number
to the first send mail, i dont receive any email, tho no errors come up and the thank you email is still sent.
why is this?

thanks for your help.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: problem with contact form send mail function

Post by Jonah Bron »

You might try checking your spam box.
gman1234
Forum Newbie
Posts: 3
Joined: Wed Sep 15, 2010 6:21 am

Re: problem with contact form send mail function

Post by gman1234 »

done that.
even if i take out the first mail and replace it with another, same issue, the first mail comand doesnt send. im lost to why
agriz
Forum Contributor
Posts: 106
Joined: Sun Nov 23, 2008 9:29 pm

Re: problem with contact form send mail function

Post by agriz »

Instead of this line

Code: Select all

mail("grenambrose@gmail.com", 'Online Form: '.$subject, $_SERVER['REMOTE_ADDR']."\n\n".$message, "From: $from");
Did you try like this ?

Code: Select all

$f_headers  = 'MIME-Version: 1.0' . "\r\n";
$f_headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$f_headers .= 'From: Some User <$from>' . "\r\n";
mail("grenambrose@gmail.com", "Subject Test", "Message", $f_headers);
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: problem with contact form send mail function

Post by Jonah Bron »

Try just creating an empty PHP file, and put this into it:

Code: Select all

<?php
mail('grenambrose@gmail.com', 'subject line', 'this is a test email');
?>
See if you get the email. Also, please edit your original post to surround your code with the syntax tags (use the PHP Code button).
Post Reply