0

I am using PHP to send data to an email address from a HTML form. It worked fine while the PHP file was a pure PHP file, displaying the confirmation text upon submitting the form. However, I needed the confirmation text to appear within our usual templates so I added the same PHP into the body of a page and set the form action to go to that page. When someone now submits the form, an email does get sent but it contains none of the information from the form. Can you help?

HTML:

<form method="post" action="thank-you-page.html"> 
 Email: <input name="email" type="text"><br />
Name: <input name="name" type="text"><br />

<h3>Your message</h3> 
Subject: <input name="subject" type="text"><br />
 Message:<br /> <textarea name="message" rows="15" cols="40"></textarea><br /> 
 <input type="submit" /> 
 </form>

PHP within body of thank-you-page.html:

<?php 
 $to = "[email protected]"; 

 $subject = 'Feedback from online form'; 
 $email = $_REQUEST['email'] ; 
 $message = $_REQUEST['message'] ; 
 $headers = "From: $email"; 
 $sent = mail($to, $subject, $message, $headers) ; 
 if($sent) 
 {print 'Your mail was sent successfully.  Thank you for your feedback.'; }
 else 
 {print 'We encountered an error sending your mail.'; }
 ?> 

Thank you!

1
  • You are posting to an html page. Unless your server is set up to process html files as php, I don't see how you can receive any mail from your script. Commented May 8, 2014 at 16:08

1 Answer 1

5

Your thank you page needs to be a PHP page, not just an HTML page.

Change it to be thank-you-page.php

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.