Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP

Kevin Woods
Kevin Woods
3,583 Points

when 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
Dean Kennedy
4,491 Points

You 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
Kevin Woods
3,583 Points

I 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