Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

php contact form

Featured Replies

Hi Guys.

 

Can anyone tell me of any good resources to set up a PHP contact form? I've tried several online 'freebies' but I can never get them to work! My hosting supports PHP so not sure what the problem is....

 

As far as I know my hosting doesn't offer a cgi script to use either.....

 

Hope someone could help, I really need to crack this!

 

Sam

  • Author
Thanks 'fruit and veg' ;) Will be sure to check this out as well, cheers for the reply....

 

Sam

 

Hi 'fruit and veg'...

 

I've been trying to get the contact form working but to no avail :(

 

I have included my email address as the recipient and uploaded the relevant files....

 

Any idea as to why it's not working?

 

I've copied the code below:-

 

Sam

 

<?php

 

$EmailFrom = "chriscoyier@gmail.com";

$EmailTo = "samdelara@btinternet.com";

$Subject = "Nice & Simple Contact Form by CSS-Tricks";

$Name = Trim(stripslashes($_POST['Name']));

$Tel = Trim(stripslashes($_POST['Tel']));

$Email = Trim(stripslashes($_POST['Email']));

$Message = Trim(stripslashes($_POST['Message']));

 

// validation

$validationOK=true;

if (!$validationOK) {

print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";

exit;

}

 

// prepare email body text

$Body = "";

$Body .= "Name: ";

$Body .= $Name;

$Body .= "\n";

$Body .= "Tel: ";

$Body .= $Tel;

$Body .= "\n";

$Body .= "Email: ";

$Body .= $Email;

$Body .= "\n";

$Body .= "Message: ";

$Body .= $Message;

$Body .= "\n";

 

// send email

$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

 

// redirect to success page

if ($success){

print "<meta http-equiv=\"refresh\" content=\"0;URL=contact-confirmation.html\">";

}

else{

print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";

}

?>

 

<form action="contactengine.php" method="post">

<label for="Name">Name:</label><br />

<input type="text" name="Name" id="Name" cols="80" rows="6" /><br /><br />

<label for="Subject">Subject:</label><br />

<input type="text" name="Subject" id="Subject" cols="40" rows="6" /><br /><br />

<label for="email-address">Email-Address:</label><br />

<input type="text" name="email-address" id="email-address" cols="40" rows="6" /><br /><br />

<label for="Enquiry">Enquiry:</label><br />

<textarea name="Enquiry" id="Enquiry" cols="20" rows="6"></textarea><br /><br />

<input type="submit" name="submit" value="Submit" />

<input name="sort" type="hidden" id="sort" value="Name,Subject,email-address,Enquiry" />

</form>

the contact page is .php?

 

contactengine.php is in the same folder as the contact page?

 

You got a link to the page?

  • Author
the contact page is .php?

 

contactengine.php is in the same folder as the contact page?

 

You got a link to the page?

 

Hi, cheers for the reply...ummm, no the contact page is html but I've referenced the form to action the php file which is in the same directory, this should work shouldn't it?

 

Link is here: http://samdelara.co.uk/contact2.html

 

Sam

I completed the form and it worked OK. Are you not receiving the email? Double check the email address...

 

$EmailFrom = "chriscoyier@gmail.com";
$EmailTo = "samdelara@btinternet.com";

 

$EmailFrom -0 can be anything, doesn't have to be an email address, this is the email's from line.

$EmailTo - this should be correct, which according to your site, it is.

 

and then your junk folder.

  • Author
I completed the form and it worked OK. Are you not receiving the email? Double check the email address...

 

$EmailFrom = "chriscoyier@gmail.com";
$EmailTo = "samdelara@btinternet.com";

 

$EmailFrom -0 can be anything, doesn't have to be an email address, this is the email's from line.

$EmailTo - this should be correct, which according to your site, it is.

 

and then your junk folder.

 

Yep, email address is correct, spam folders checked and I also tried my google mail address..

 

Cannot understand why this won't work for me :(

 

Any ideas? Is it my hosting perhaps? I know that PHP 5 is supported...

 

Grrrrr......

  • Author
Yep, email address is correct, spam folders checked and I also tried my google mail address..

 

Cannot understand why this won't work for me :(

 

Any ideas? Is it my hosting perhaps? I know that PHP 5 is supported...

 

Grrrrr......

 

Right, I'm really confused now - I have tested the PHP mail scripting funtion through my hosting control panel and it is working fine.....

I've just tested your code on my hosting and it works fine. Is your email working OK in general? If so, then it looks like your hosting is not emailing the message to you to begin with rather than it being an email problem.

  • Author
I've just tested your code on my hosting and it works fine. Is your email working OK in general? If so, then it looks like your hosting is not emailing the message to you to begin with rather than it being an email problem.

 

That's the strange thing, I don't think it is the hosting as their test scripts are working fine.....is there some sort of security measure that is preventing this script from working do you think?

 

Sam

That's the strange thing, I don't think it is the hosting as their test scripts are working fine.....is there some sort of security measure that is preventing this script from working do you think?

 

Sam

 

 

Hi Sam,

 

Two things you need to check.

 

1) smtp gateway is set

2) safe_mode is set to off

 

You can check this by creating a file in notepad called test.php. Within this file put the following commands :

 

<?php

 

phpinfo();

 

?>

 

Then call test.php in your broswer. You should see a whole load of config settings for php. These are the settings and functions that your hosting provider allows you to do through php. Just do a search for smtp and safe_mode (Safe_mode is set to off and smtp has a gateway assigned to it).

 

If these settings do not conform to what I stated then your hosting has disallowed it.

 

But your hosting can block emails as a security measure because of spamming, in which case you need to tell them that you would like this service. Some times they may black list you because some one else has used your email address for spamming.

 

Hope this helps

 

 

and Good luck

haha - that makes sense - thank you Mihai. I was on the verge of getting totally confused. :D

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.