Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
Simple PHP Help, Contact Form?
I am making a contact form and I can't get this page to open a HTML file after the form has been sent via e-mail. Can someone please just help me out thanks. Here's the code;
<?php
if(isset($_POST['submit'])) {
$to = "*****@*****.com";
$subject = "Contact Form";
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$message = $_POST['message'];
$body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message";
echo "Data has been submitted to $to!";
mail($to, $subject, $body);
} else {
echo "blarg!";
}
I have tried putting in thankyou.html into the space where i thought it was ment to go but it doesn't work. I think i need another code to go there but i don't know what. I haven't worked with PHP before and i am tryng to learn it but i just can't work it out
Ok So I have a page set up called contact.html which has the form on it. That links to a php document that sends the data via e-mail and normally echo the message above but instead i just want it to send the user to another page
6 Answers
- Anonymous1 decade agoFavorite Answer
replace
echo "Data has been submitted to $to";
with
header("location: thankyou.php");
OR
Where the echo "Data has been submitted to $to";
is, replace that with your thank you code. The form should post to ITSELF.
<form method="post" action="<? $_SERVER['PHP_SELF']; ?>">
qualify as the area you are trying to code new html?
- Anonymous1 decade ago
I would take this:
echo "Data has been submitted to $to!";
mail($to, $subject, $body);
and turn it into this
if(mail($to, $subject, $body)){
echo "success";
}else{
echo "failure";
}
tis way you are actually testing the mail function to ensure that it is sending (mail() returns a binary value)
- korgrueLv 71 decade ago
Here is what I use on my site. It echos back the info, forwards the contact to my email address, and writes the contact info to a file outside of my web directory.
Feel free to use and edit as necessary.
<?php
//echo form data to screen, create body for email and for file
$todaysdate = date("m",time()) . "-" . date("d",time()) . "-" . date("Y",time()) . " " . date("h",time()) . ":" . date("i",time()) . date("a",time());
$email_body = "Date: " . $todaysdate . "\n";
$file_data = $todaysdate;
echo "<ul>";
echo "The following information has been submitted:";
foreach ($_POST as $key => $value) {
if ($key <> "submit") {
echo "<li><strong>$key:</strong> $value</li>\n";
$email_body = $email_body . $key . ": ".$value ."\n";
$file_data = $file_data ."|".$value;
}
}
echo "</ul>";
//send email
//$emailTime = date_str($timestamp);
$destination_email="xxxxx@xxx.com";
$email_subject="Customer info for ".$_POST['name'];
mail($destination_email,$email_subject,$email_body);
$myfileName = "../files/customers.txt";
//$myPointer = fopen($myfileName, "a+") or die("can't open file");
$myPointer = fopen($myfileName, "a+");
if (!$myPointer) {
echo "File couldn't be opened";
} else {
fputs($myPointer, $file_data);
fclose($myPointer);
}
?>
- Anonymous1 decade ago
You have a form somewhere right?
<form action="contact.php" method="post">
The action should be the page where you're sent to after the form.
- How do you think about the answers? You can sign in to vote the answer.