Jump to content

Form to Mail


AnonymousX
 Share

Recommended Posts

I've never used PHP so please go easy on me. I've been trying to get this script to work, but haven't the slightest idea as to what is wrong with it. Here is the code I am working with.I put this code into a file called mail.php and yes, I have my email address in my form, I changed it for security reasons.

"<?php//variables (change these)$youremail = "myemail@domain.com";// email$subject = "Contact";// email subject$thankyou = "thankyou.html";// redirect;if($email == ""){?>No email address added. Please go back.<br/>"<?php;}elseif($name == ""){"?>No name added. Please go back.<br/><?php;}elseif($message == ""){"?>No message added. Please go back.<br/>"<?php;}else{$msg = ereg_replace("\\\'", "'", $message);$msg = ereg_replace('\\\"', "\"", $msg);$message1 = "from: $name\nemail: $email\nmessage:\n$msg1";mail($youremail, $subject, $msg, "From: $email\r\nReply-to: $email\r\n");?><meta http-equiv="refresh" content="0; url=<?echo $thankyou;?>"">"<?php}"?>

I have this code in my body.

<form action="mail.php" method="post">Name:<input type="text" name="name"><br/><br/>Email: <input type="text" name="email"><br/><br/>Message:<br/><br/><textarea name="message" cols="40" rows="15"></textarea><br/><br /><input type="submit" value="Submit"><br/></form>

And this is what displays on the screen after clicking the submit button. It is a screen with the text from my php document.

"<?php//variables (change these)$youremail = "smith_d88@hotmail.com";// your email address$subject = "Contact";// the subject of the email$thankyou = "thankyou.html";// thank you page// don't change anything else;if($email == ""){?>No email address added. Please go back.<br/>"<?php;}elseif($name == ""){"?>No name added. Please go back.<br/><?php;}elseif($message == ""){"?>No message added. Please go back.<br/>"<?php;}else{$msg = ereg_replace("\\\'", "'", $message);$msg = ereg_replace('\\\"', "\"", $msg);$message1 = "from: $name\nemail: $email\nmessage:\n$msg1";mail($youremail, $subject, $msg, "From: $email\r\nReply-to: $email\r\n");?><meta http-equiv="refresh" content="0; url=<?echo $thankyou;?>"">"<?php}"?>

Link to comment
Share on other sites

If it's showing the PHP code then the server is not set up to run PHP. Make sure you have PHP installed and configured with the web server. You'll also need to get all the variables from $_POST before you use them:$email = $_POST['email'];$name = $_POST['name'];$message = $_POST['message'];It's not a good practice to rely on register_globals being enabled, it's not even a good practice to enable it.Also, I'm not sure where they came from, but there are several quotes that should be removed."<?php//variables (change these)$youremail = "myemail@domain.com";// email$subject = "Contact";// email subject$thankyou = "thankyou.html";// redirect;if($email == ""){?>No email address added. Please go back.<br/>"<?php;}elseif($name == ""){"?>No name added. Please go back.<br/><?php;}elseif($message == ""){"?>No message added. Please go back.<br/>"<?php;}else{$msg = ereg_replace("\\\'", "'", $message);$msg = ereg_replace('\\\"', "\"", $msg);$message1 = "from: $name\nemail: $email\nmessage:\n$msg1";mail($youremail, $subject, $msg, "From: $email\r\nReply-to: $email\r\n");?><meta http-equiv="refresh" content="0; url=<?echo $thankyou;?>"">"<?php}"?>You can also remove any semicolon that you see at the start of a line. They aren't going to break anything, but they aren't necessary either.

Link to comment
Share on other sites

Rather than starting a new topic, I'm just going to continue here. I have made my PHP form to mail work with a different script. However, I have been getting an error message. After I submit the form the first time, if I return to the contact page, I often find this in my content.Warning: Cannot modify header information - headers already sent by (output started at /hsphere/local/home/smithd88/adhesionarts.com/index.php:9) in /hsphere/local/home/smithd88/adhesionarts.com/index.php on line 95I don't know what it means or what is causing it but line 95 reads...header("location: thankyou.html");I can only assume that I have failed in my attempt to redirect the visitor to a thank you page after submitting the form. If this is not enough information, please tell me and I can give the code.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...