Sacki Posted October 1, 2013 Share Posted October 1, 2013 Hi, I have been trying for days to get a contact form to email data on a clients site. I am good with html and css but new to PHP so sorry if i see clueless. Watched numerous videos and read plenty of tutorials and other questions. The problem is as follows: I have created the site here is a link to the test php page i created www.peoplespropertyshop.co.uk/test.php in this file i have the following: <h1>Contact Form</h1> <form action="thankyou.php" method="post"> Name <input type="text" name="fullname"><br> Email <input type="text" name="email"><br> Message <textarea name="message"></textarea><br> <input type="submit" value="Submit"> </form> </body> </html> then i have the below code from the thankyou.php:- <? $name = $GET_POST['fullname']; $email = $GET_POST['email']; $message = $GET_POST['message']; $email_message = " Name:".$name." Email:".$email." Message:".$message." "; mail ( "info@peoplespropertyshop.co.uk" , "New Enquiry" , "$email_message"); header("Location: email_success.php"); ?> I also have the file named email_success.php. All these files are live on the domain bought through 1 and 1 and is hosted for free by 000webhost whom do support php mail on there free accounts. This is a simple form i have been using to practice as i was sick of taking the contact form from the actual site down. I have no testing server as the i am uploading via FTP to test the,. Does anybody have any advice. As i say i am very new to php. Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/282605-php-contact-form/ Share on other sites More sharing options...
TOA Posted October 1, 2013 Share Posted October 1, 2013 instead of $name = $GET_POST['fullname']; $email = $GET_POST['email']; $message = $GET_POST['message']; try $name = $_POST['fullname']; $email = $_POST['email']; $message = $_POST['message']; And it would be a good idea to read up on GET and POST in the manual. Quote Link to comment https://forums.phpfreaks.com/topic/282605-php-contact-form/#findComment-1452036 Share on other sites More sharing options...
Sacki Posted October 1, 2013 Author Share Posted October 1, 2013 instead of $name = $GET_POST['fullname']; $email = $GET_POST['email']; $message = $GET_POST['message']; try $name = $_POST['fullname']; $email = $_POST['email']; $message = $_POST['message']; And it would be a good idea to read up on GET and POST in the manual. Thanks i dont know why i had GET and POST in there i did read up what each does. I tried what you said with the $_POST and still the same it gives me this webpage error http://error404.000webhost.com/? Thanks for reply really appreciated Quote Link to comment https://forums.phpfreaks.com/topic/282605-php-contact-form/#findComment-1452037 Share on other sites More sharing options...
TOA Posted October 1, 2013 Share Posted October 1, 2013 That shouldn't be the case if both thankyou.php and email_success.php exist. Try full php opening tags: <?php instead of <? It might be that your server doesn't recognize shorttags.. Quote Link to comment https://forums.phpfreaks.com/topic/282605-php-contact-form/#findComment-1452046 Share on other sites More sharing options...
Sacki Posted October 1, 2013 Author Share Posted October 1, 2013 That shouldn't be the case if both thankyou.php and email_success.php exist. Try full php opening tags: <?php instead of <? It might be that your server doesn't recognize shorttags.. Thanks for reply its driving me mad. Changed the opening tags as you suggested but still nothing. I have tried this with new email address' created on 1 and 1 where site is registered and with 00webhost where hosted and even to reg email address but still the same. Do you think its host issue as the code looks like it should work to me? Thanks again mate Quote Link to comment https://forums.phpfreaks.com/topic/282605-php-contact-form/#findComment-1452048 Share on other sites More sharing options...
Ch0cu3r Posted October 1, 2013 Share Posted October 1, 2013 Have you sorted the issue now? as the test.php at peoplespropertyshop.co.uk appears to be working fine now. Quote Link to comment https://forums.phpfreaks.com/topic/282605-php-contact-form/#findComment-1452050 Share on other sites More sharing options...
cyberRobot Posted October 1, 2013 Share Posted October 1, 2013 Just to clarify, is the email not being sent...or is the redirect not working? Or both? Also note that you should test if the mail() function was successful before redirecting the page. <? if(mail ( "info@peoplespropertyshop.co.uk" , "New Enquiry" , "$email_message")) { header("Location: email_success.php"); } else { //mail failed, log error; display message; or whatever here } ?> Quote Link to comment https://forums.phpfreaks.com/topic/282605-php-contact-form/#findComment-1452051 Share on other sites More sharing options...
Sacki Posted October 1, 2013 Author Share Posted October 1, 2013 Have you sorted the issue now? as the test.php at peoplespropertyshop.co.uk appears to be working fine now. No not sorted yet. It gives me the success page like you saw but i never receive the mail Quote Link to comment https://forums.phpfreaks.com/topic/282605-php-contact-form/#findComment-1452052 Share on other sites More sharing options...
Sacki Posted October 1, 2013 Author Share Posted October 1, 2013 (edited) Just to clarify, is the email not being sent...or is the redirect not working? Or both? Also note that you should test if the mail() function was successful before redirecting the page. <? if(mail ( "info@peoplespropertyshop.co.uk" , "New Enquiry" , "$email_message")) { header("Location: email_success.php"); } else { //mail failed, log error; display message; or whatever here } ?> The redirect is working and it states success but the mail never arrives i am unsure if its domain error or mine as i am new to php. Yeah i took out the else for the time being as just wanted to get it to send Edited October 1, 2013 by Sacki Quote Link to comment https://forums.phpfreaks.com/topic/282605-php-contact-form/#findComment-1452054 Share on other sites More sharing options...
cyberRobot Posted October 1, 2013 Share Posted October 1, 2013 The redirect is working and it states success but the mail never arrives i am unsure if its domain error or mine as i am new to php Did you add the if test to make sure it's working? The mail() function returns false if it isn't accepted for delivery: http://php.net/manual/en/function.mail.php Quote Link to comment https://forums.phpfreaks.com/topic/282605-php-contact-form/#findComment-1452055 Share on other sites More sharing options...
Ch0cu3r Posted October 1, 2013 Share Posted October 1, 2013 For a test, comment out the header line, by adding two forward slashes at the start of the header line. Run your code. Do you get the email now? Also make sure you're checking your spam filter too. Quote Link to comment https://forums.phpfreaks.com/topic/282605-php-contact-form/#findComment-1452056 Share on other sites More sharing options...
Sacki Posted October 1, 2013 Author Share Posted October 1, 2013 Did you add the if test to make sure it's working? The mail() function returns false if it isn't accepted for delivery: http://php.net/manual/en/function.mail.php Hi sorry but what part of that link am i looking for its a long page and can't seem to locate an "if" test Thanks Quote Link to comment https://forums.phpfreaks.com/topic/282605-php-contact-form/#findComment-1452059 Share on other sites More sharing options...
Sacki Posted October 1, 2013 Author Share Posted October 1, 2013 For a test, comment out the header line, by adding two forward slashes at the start of the header line. Run your code. Do you get the email now? Also make sure you're checking your spam filter too. Tried doing as you suggested and commented out the headers line. Still didnt get the email. Checked spam nothing there either. Thanks for response Quote Link to comment https://forums.phpfreaks.com/topic/282605-php-contact-form/#findComment-1452061 Share on other sites More sharing options...
cyberRobot Posted October 1, 2013 Share Posted October 1, 2013 Hi sorry but what part of that link am i looking for its a long page and can't seem to locate an "if" test Thanks Sorry for the confusion...the "if" test I was referring to can be found in Response #7. I'm not sure why the manual doesn't include an example which tests for the mail() function being successful. Another thing to consider is maybe the mail server is busy. I've had messages that took up to an hour to make their way through the system. Quote Link to comment https://forums.phpfreaks.com/topic/282605-php-contact-form/#findComment-1452062 Share on other sites More sharing options...
Sacki Posted October 1, 2013 Author Share Posted October 1, 2013 Sorry for the confusion...the "if" test I was referring to can be found in Response #7. I'm not sure why the manual doesn't include an example which tests for the mail() function being successful. Another thing to consider is maybe the mail server is busy. I've had messages that took up to an hour to make their way through the system. Thanks for that will look into now. Been at it all day and nothing come through to several email accounts. Thanks again Quote Link to comment https://forums.phpfreaks.com/topic/282605-php-contact-form/#findComment-1452064 Share on other sites More sharing options...
Sacki Posted October 1, 2013 Author Share Posted October 1, 2013 Sorry for the confusion...the "if" test I was referring to can be found in Response #7. I'm not sure why the manual doesn't include an example which tests for the mail() function being successful. Another thing to consider is maybe the mail server is busy. I've had messages that took up to an hour to make their way through the system. Is this what you are referring to $ok=mail($To, $Subject, $Body, $Headers); echo $ok?"<h1> Mail Sent</h1>":"<h1> Mail not SEND</h1>"; ?> Sorry to be a pain Quote Link to comment https://forums.phpfreaks.com/topic/282605-php-contact-form/#findComment-1452065 Share on other sites More sharing options...
cyberRobot Posted October 1, 2013 Share Posted October 1, 2013 Is this what you are referring to $ok=mail($To, $Subject, $Body, $Headers); echo $ok?"<h1> Mail Sent</h1>":"<h1> Mail not SEND</h1>"; ?> Sorry to be a pain Yep, that should work. Well, I can't promise the email will be sent, but you have the idea. Quote Link to comment https://forums.phpfreaks.com/topic/282605-php-contact-form/#findComment-1452067 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.