Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need help please

Status
Not open for further replies.

edd1e19

Programmer
Joined
Mar 22, 2004
Messages
72
Location
GB
Hi there,

I'm trying to create a contact form using php.
If you go to and fill in the form then submit it, it goes to another page called sendeail.php. But when i check my email there is no information of what i typed into the fields in the contact.php page.

I'm trying to follow this tutorial
If anyone could help, that would be very much apprecited.

Thanks

Edd
 
The example on that page will not work when the PHP directive register_globals is turned off as it is by default in all PHP versions since 4.3.0.

To make the example work, change the following code
Code:
if (!isset($visitormail))
echo "Somebody Goofed $ip" ;

$todayis = date("l, F j, Y, g:i a") ;

$subject = "Visitor Mail" ;

$message = " $todayis [EST] \n
Message: $notes \n
From: $visitor ($visitormail)\n
Additional Info : IP = $ip \n
Browser Info: $httpagent \n
Referral : $httpref \n
to
Code:
if (!isset($_POST['visitormail']))
echo "Somebody Goofed $ip" ;

$todayis = date("l, F j, Y, g:i a") ;

$subject = "Visitor Mail" ;

$message = " $todayis [EST] \n
Message: $_POST['notes'] \n
From: $_POST['visitor'] ($_POST['visitormail'])\n
Additional Info : IP = $_POST['ip'] \n
Browser Info: $_POST['httpagent'] \n
Referral : $_POST['httpref'] \n

And then read about register_globals and security in the online PHP manual at
Ken
 
First out, make sure your server is set up with sendmail.

If thats ok, try using this and see if you get any results
Save this as an html page.
Code:
<html>
<head>
<title>Form to send mail</title>
</head>
<body>
<form action="email.php" method="post">
Name <input type="text" name="name"><br>
Email <input type="text" name="email"><br>
Message <textarea name="message" cols="30" rows="5"></textarea><br>
<input type="submit" value="send form">
</form>
</body>
</html>

save this as email.php
Code:
<html>
<head>
<title>Send Email</title>
</head>
<body>
<?php
 
$name=trim($name);
$email=trim($email);
$message=trim($message);

print "Name = " .$name. "<br>\n\n";
print "Email = " .$email. "<br>\n\n";
print "Message = " .$message. "<br>\n\n";

$msg = "Customers Name: ".$name." \r\n"
."Customers Email: ".$email."\r\n"
."Customers Message: ".$message."\r\n";

$recipient = "you@yourdomain.com";
$subject = "testing email";
$mailheaders = "From: Website Name <defaultaddress@yourdoamin.com> \n";
$mailheaders .= "Reply -To:" .$email;

mail($recipient, $subject, $msg, $mailheaders);
?>
</body>
</html>

you should see the information being passed to this page and to your email address. (obviously you need to adjust the email addresses to match with yours)

Sometimes, when my code just won't behave, I take it outside and make it listen to britney spears music, and when it comes back it's really well behaved. I wonder if it's suffering from post tramatic stress syndrome now..
 
hi kenrbnsn,

if you go to and fill in the fields then submit it, you will see i get an error:

Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/enigma/public_html/sendeail.php on line 19

Line 19 is:

Message: $_POST['notes'] \n

Do you know what could be wrong?

Thanks

Ed
 
You are getting that error because it is illegal to concatenate a sting with a variable where single quotes are being ues in the array pointer. This is one of the very few restrictions you must adhere to. Using that logic, we now have:
Code:
if (!isset($_POST['visitormail']))
echo "Somebody Goofed $ip" ;

$todayis = date("l, F j, Y, g:i a") ;

$subject = "Visitor Mail" ;

$message = " $todayis [EST] \n
Message: ".$_POST['notes']." \n
From: ".$_POST['visitor']." (".$_POST['visitormail'].")\n
Additional Info : IP = ".$_POST['ip']." \n
Browser Info: ".$_POST['httpagent']." \n
Referral : ".$_POST['httpref']." \n";

___________________________________
[morse]--... ...--[/morse], Eric.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top