-
HTML, PHP Contact form
I've followed some tutorials from the internet about making a HTML and PHP contact form, all went well (i can receive emails using the form) except when i try to redirect it to a new HTML page after submitting the email, it shows an error.
Warning: Cannot modify header information - headers already sent by (output started at /home/jasonro/public_html/speakartdesign/clients/plaxeld/contact.php:2) in /home/jasonro/public_html/speakartdesign/clients/plaxeld/contact.php on line 17
PHP Code:
<?
$subject="from ".$_POST['your_name'];
$headers= "From: ".$_POST['your_email']."\n";
$headers.='Content-type: text/html; charset=iso-8859-1';
mail("me@jasonpang.com", $subject, "
<html>
<head>
<title>Contact letter</title>
</head>
<body>
<br>
".$_POST['message']."
</body>
</html>" , $headers);
header('Location: sent.html');
?>
If i don't put that last line, header('Location: sent.html');, it'll go to a blank page, but that's not what i want. I want it to be redirected to a page where it says that their email has been sent, but it doesn't work if i put that header('Location: index.html');.
-
Bearded (M|G)od
To use a header() call, no other output can be present before that call is made. Not even white space. So to me, it seems that there is probably a line break ABOVE your starting PHP tag, or a space, or something of that sort. Unless you're not posting the whole script and have some kind of echo statements somewhere.
Check around for that, if you're still having an issue, post up your entire php file.
-
Bearded (M|G)od
Actually, upon some closer inspection, it seems that you have a linebreak before your starting PHP tag. I say this because your error is pointing to line 17 of the file.
In the code you posted, the header() call is on line 16. So there has to be an empty line above that you didn't paste here.
-
Someone from my hosting support offered me a solution. Instead of redirecting, I can put my html code down there.
PHP Code:
<?php
$message = ''; $success = false;
foreach($_POST as $t => $v) $message .= $t.': '.$v."\n\n";
if( strlen($message) > 2) { $message = "Someone recently used the form submission. Here are the details:\n\n".$message; $success = mail ( "me@jasonpang.com" , "Form Sumission" , $message ); }
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> </head> <body> </body> </html>
-
Bearded (M|G)od
Yeah, there is that. But I was trying more to fix your error.
-
Thanks taco
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|