tomala90 Posted October 31, 2009 Share Posted October 31, 2009 Hi guys I really need your help. I am new to PHP. I am trying to make an email form on my website but I keep getting some kinds of error Here is the code <?php $to = "[email protected]"; $subject = "Contact Us"; $email = $_REQUEST['email'] ; $message = $_REQUEST['message'] ; $headers = "From: $email"; $sent = mail($to, $subject, $message, $headers) ; if($sent) {print "Your mail was sent successfully"; } else {print "We encountered an error sending your mail"; } ?> and that is my HTML form <form action="?" method="post"> Email: <input name="email" type="text"><br> <input type="submit"> </form> I want to add that I am not running the form and the scrip in one file. Link to comment https://forums.phpfreaks.com/topic/179705-solved-need-help-wih-mail/ Share on other sites More sharing options...
trq Posted October 31, 2009 Share Posted October 31, 2009 I keep getting some kinds of error And they would be? You are aware you have no 'message' element in your form? Link to comment https://forums.phpfreaks.com/topic/179705-solved-need-help-wih-mail/#findComment-948165 Share on other sites More sharing options...
tomala90 Posted October 31, 2009 Author Share Posted October 31, 2009 Errors like "unexpected T_STRING" This may be all wrong because I am really new to PHP Link to comment https://forums.phpfreaks.com/topic/179705-solved-need-help-wih-mail/#findComment-948169 Share on other sites More sharing options...
trq Posted October 31, 2009 Share Posted October 31, 2009 There are no parse errors in your php, again I say however that you have no 'message' element in your form. <form action="script.php" method="post"> Email: <input name="email" type="text"><br> Message: <input name="message" type="text"><br> <input type="submit"> </form> Notice also that the forms action needs to point to your php script. Link to comment https://forums.phpfreaks.com/topic/179705-solved-need-help-wih-mail/#findComment-948170 Share on other sites More sharing options...
tomala90 Posted October 31, 2009 Author Share Posted October 31, 2009 Ok I will try it in a minute and I will let you know if that works Link to comment https://forums.phpfreaks.com/topic/179705-solved-need-help-wih-mail/#findComment-948172 Share on other sites More sharing options...
tomala90 Posted October 31, 2009 Author Share Posted October 31, 2009 I tried it and that's what displayed on my monitor " Parse error: syntax error, unexpected T_STRING in /home/a7576050/public_html/email.php on line 8 " Link to comment https://forums.phpfreaks.com/topic/179705-solved-need-help-wih-mail/#findComment-948176 Share on other sites More sharing options...
tomala90 Posted October 31, 2009 Author Share Posted October 31, 2009 Any ideas how to fix it ? Link to comment https://forums.phpfreaks.com/topic/179705-solved-need-help-wih-mail/#findComment-948181 Share on other sites More sharing options...
trq Posted October 31, 2009 Share Posted October 31, 2009 Post your current and actual code. Link to comment https://forums.phpfreaks.com/topic/179705-solved-need-help-wih-mail/#findComment-948192 Share on other sites More sharing options...
tomala90 Posted October 31, 2009 Author Share Posted October 31, 2009 <html><body> <center><br><br><br><br><br><br><br> <form action="email.php" method="post"> Email: <input name="email" type="text"><br> Message: <input name="message" type="text"><br> <input type="submit"> </form> </body> </html> <?php $to = "[email protected]"; $subject = "Contact Us"; $email = $_REQUEST['email'] ; $message = $_REQUEST['message'] ; $headers = "From: $email"; $sent = mail($to, $subject, $message, $headers) ; if($sent) {print "Your mail was sent successfully"; } else {print "We encountered an error sending your mail"; } ?> Link to comment https://forums.phpfreaks.com/topic/179705-solved-need-help-wih-mail/#findComment-948194 Share on other sites More sharing options...
trq Posted October 31, 2009 Share Posted October 31, 2009 There is no way that code could possibly throw that error, but lets indent your code properly so it is more readable and errors are easier to spot. <?php $to = "[email protected]"; $subject = "Contact Us"; $email = $_REQUEST['email'] ; $message = $_REQUEST['message'] ; $headers = "From: $email"; $sent = mail($to, $subject, $message, $headers) ; if ($sent) { print "Your mail was sent successfully"; } else { print "We encountered an error sending your mail"; } ?> Nope, still no errors found. Link to comment https://forums.phpfreaks.com/topic/179705-solved-need-help-wih-mail/#findComment-948199 Share on other sites More sharing options...
svgmx5 Posted October 31, 2009 Share Posted October 31, 2009 You have errors bud.... i tested the script right now, and got the email just right to my inbox Link to comment https://forums.phpfreaks.com/topic/179705-solved-need-help-wih-mail/#findComment-948201 Share on other sites More sharing options...
tomala90 Posted October 31, 2009 Author Share Posted October 31, 2009 I got organize my files, and you are right the message sends I got "Your mail was sent successfully " on the screen. However I do not get any email in my inbox. Do I need any other bit of code to make this work correctly ? Link to comment https://forums.phpfreaks.com/topic/179705-solved-need-help-wih-mail/#findComment-948203 Share on other sites More sharing options...
svgmx5 Posted October 31, 2009 Share Posted October 31, 2009 Well i did notice your email was not right, unless its [email protected] Link to comment https://forums.phpfreaks.com/topic/179705-solved-need-help-wih-mail/#findComment-948205 Share on other sites More sharing options...
tomala90 Posted October 31, 2009 Author Share Posted October 31, 2009 Good point ! there is an "h" before gmail.com I am gonna change it and try it out Link to comment https://forums.phpfreaks.com/topic/179705-solved-need-help-wih-mail/#findComment-948207 Share on other sites More sharing options...
tomala90 Posted October 31, 2009 Author Share Posted October 31, 2009 It works Thank you guys for good and quick help ! Link to comment https://forums.phpfreaks.com/topic/179705-solved-need-help-wih-mail/#findComment-948211 Share on other sites More sharing options...
svgmx5 Posted October 31, 2009 Share Posted October 31, 2009 no problem, just remember to put the email correct Link to comment https://forums.phpfreaks.com/topic/179705-solved-need-help-wih-mail/#findComment-948213 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.