Jump to content

PHP Contact Form.


Sacki

Recommended Posts

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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
}
?>
Link to comment
Share on other sites

 

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 by Sacki
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

 

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

Link to comment
Share on other sites

 

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.