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 = "myemail@hgmail.com"; $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. Quote Link to comment 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? Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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 " Quote Link to comment Share on other sites More sharing options...
tomala90 Posted October 31, 2009 Author Share Posted October 31, 2009 Any ideas how to fix it ? Quote Link to comment Share on other sites More sharing options...
trq Posted October 31, 2009 Share Posted October 31, 2009 Post your current and actual code. Quote Link to comment 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 = "myemail@hgmail.com"; $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"; } ?> Quote Link to comment 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 = "myemail@hgmail.com"; $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. Quote Link to comment 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 Quote Link to comment 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 ? Quote Link to comment 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 myemail@hgmail.com Quote Link to comment 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 Quote Link to comment 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 ! Quote Link to comment 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 Quote Link to comment 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.