wero86 Posted April 26, 2009 Share Posted April 26, 2009 Hi guys am new to php script and need to get the information entered into my form sent to me via email. the froms code is as follows: <form action="Test/sendinfo.php" name="Contact" id="Contact"> <table width="90%" border="0" cellspacing="2" cellpadding="4"> <tr> <td width="14%" align="right" valign="top">Name:</td> <td width="86%" colspan="2" valign="top"><input name="name" type="text" id="name" size="30" /></td> </tr> <tr> <td width="14%" align="right" valign="top">Email:</td> <td colspan="2" valign="top"><input name="email" type="text" id="email" size="30" /></td> </tr> <tr> <td align="right" valign="top">Tel:</td> <td colspan="2" valign="top"><input name="tel" type="text" id="tel" size="30" /></td> </tr> <tr> <td width="14%" align="right" valign="top">Subject:</td> <td colspan="2" valign="top"><input name="subject" type="text" id="subject" size="30" /></td> </tr> <tr> <td valign="top" align="right" width="14%">Message:</td> <td colspan="2" valign="top"><textarea name="message" cols="30" rows="5" id="message"></textarea></td> </tr> <tr> <td width="14%" align="right"> </td> <td colspan="2"><input name="Submit" type="submit" onclick="MM_validateForm('name','','R','email','','RisEmail','tel','','RisNum','message','','R');return document.MM_returnValue" value="Send" /> <input name="Clear" type="reset" id="Clear" value="Clear" /></td> </tr> </table> </form> I did have an attempt after looking at several examples and came up with the following however it doesnt work :-( <?php $email_to = "...........@.....................co.uk"; $name = $_POST["name"]; $email_from = $_POST["email"]; $message = $_POST["message"]; $email_subject = "Feedback from website"; $headers = "From: $email_from .\n"; "Reply-To: $email_from .\n"; $message = "Name: ". $name . "\r\nMessage: " . $message; ini_set("sendmail_from", $email_from); $sent = mail($email_to, $email_subject, $message, $headers, "-f" .$email_from); if ($sent) { header("Location: http://www..................................co.uk/thankyou.html"); } else { echo "There has been an error sending your comments. Please try later."; } ?> i do want to try and get all the info but for my first attempt i just tried to get the name email and message but if any1 can help me get all of it that would be great :-) Quote Link to comment https://forums.phpfreaks.com/topic/155716-form-script-help/ Share on other sites More sharing options...
GingerRobot Posted April 26, 2009 Share Posted April 26, 2009 So do you receive the error message ("There has been an error sending your comments. Please try later")? Or do you get redirected, but receive no email/an incorrect email? Or is there some other problem? Also, in future wrap your code in tags - it helps us read what you've posted Quote Link to comment https://forums.phpfreaks.com/topic/155716-form-script-help/#findComment-819640 Share on other sites More sharing options...
ignace Posted April 26, 2009 Share Posted April 26, 2009 $headers = "From: $email_from .\n"; "Reply-To: $email_from .\n"; is wrong and should be: $headers = "From: $email_from\n". "Reply-To: $email_from\n"; -------------------------------------- ini_set("sendmail_from", $email_from); why set the from twice? -------------------------------------- i would really encourage adding some anti-spam method and some validation on everything what you get from $_POST -------------------------------------- P.S. use ' (single quote) instead of " (double quote) only use double if you need to parse something in the string like: $headers = "From: $email_from\n". "Reply-To: $email_from\n"; otherwise use ' (single quote) Quote Link to comment https://forums.phpfreaks.com/topic/155716-form-script-help/#findComment-819641 Share on other sites More sharing options...
wero86 Posted April 26, 2009 Author Share Posted April 26, 2009 hi i just get page cant be displayed and no email!!!! as i said am new to this so just tryin to get started then ill look into validation and anti spam! any help is greatly appreciated Quote Link to comment https://forums.phpfreaks.com/topic/155716-form-script-help/#findComment-819648 Share on other sites More sharing options...
GingerRobot Posted April 26, 2009 Share Posted April 26, 2009 Which page cannot be displayed, sendinfo.php or thankyou.html? Quote Link to comment https://forums.phpfreaks.com/topic/155716-form-script-help/#findComment-819650 Share on other sites More sharing options...
premiso Posted April 26, 2009 Share Posted April 26, 2009 <?php $email_to = "...........@.....................co.uk"; $name = $_POST["name"]; $email_from = $_POST["email"]; $message = $_POST["message"]; $email_subject = "Feedback from website"; $headers = "From: $email_from \r\n"; $headers .= "Reply-To: $email_from \r\n"; $message = "Name: ". $name . "\r\nMessage: " . $message; // ini_set("sendmail_from", $email_from); // not sure if this is needed, but I do not think so (unless your host says different). $sent = mail($email_to, $email_subject, $message, $headers, "-f" .$email_from); if ($sent) { header("Location: http://www..................................co.uk/thankyou.html"); }else { echo "There has been an error sending your comments. Please try later."; } ?> For the headers (if on linux) you need to use \r\n Give that a try and see what comes of it. Also, the email being sent to may be the issue, as Yahoo, Hotmail and AOL block most mail coming from php servers if the server ip does not have a mail MX record, so that could be your problem. Quote Link to comment https://forums.phpfreaks.com/topic/155716-form-script-help/#findComment-819651 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.