Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialKevin Woods
3,583 Pointswhen i submit a form it goes to the php page. how do I make that not happen
HTML
<form action= "email.php" method= "post" id= "form"> <label for= "name">Name:</label> <input type= "text" id= "name" name= "user_name"> <label for= "email">Email:</label> <input type= "email" id= "email" name= "user_email"> <label for= "phone">Phone Number:</label> <input type= "text" id= "phone" name= "user_phone"> <label for= "needs">Needs:</label> <textarea id= "needs" name= "user_needs"></textarea> <button id= "submit" value= "send-form" >Submit</button> </form>
PHP
<?php
//set form strings
$email = $_post[email]; $name = $_post[name]; $phone = $_post[phone]; $message = $_post[needs];
//compose message
$email_from = 'ctenser@tenserhaus.com'; $email_subject = "New Form submission"; $email_body = "You have received a new message from the user $name.\n" "The phone number is $phone.\n" "The E-mail is $email.\n" "Here is the message:\n $message";
//send email
$to = "n3v1kk@gmail.com"; $headers = "From: $email_from \r\n"; $headers .= "Reply-To: $email \r\n"; //mail($to,$email_subject,$email_body,$headers);
?>
2 Answers
Dean Kennedy
4,491 PointsYou are telling it to send the information from the form to email.php (form action= "email.php"), is this not the action you require?
Kevin Woods
3,583 PointsI want it to send the information from the form to the php, which should then send an email. It should also stay on the original page. When i click submit though it goes to a blank page with the php address in the adress field