HTML Contact Form

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Dingus

Thread Starter
Joined
Apr 21, 2002
Messages
1,191
Hi folks.
I'm looking for some code for a contact form for my website, or a site that does this coding.
I did find a site that constructed a form a while ago but this has now stopped working.
 

Dingus

Thread Starter
Joined
Apr 21, 2002
Messages
1,191
Thanks SpywareDr.
This is perfect for me. I only need to do a few tweaks.
Then work out how pho gets it submitted.
 

Dingus

Thread Starter
Joined
Apr 21, 2002
Messages
1,191
OK folks.
I now have a form (Thanks to SpywareDR) that does what I need, but when I get the info sent to my website I get this error message.

( ! ) Parse error: syntax error, unexpected '?> ' in D:\wamp64\www\EmailForm\action_page.php on line 12
Line 12 only has ?> in it, which I thought just closed the PHP.

This is my action_page.php file:

<!doctype html>
<html>
<body>
<?php
$email_from = 'jondoe@gmail.com';
$email_subject = "New Form submission";
$email_body = "You have received a new message from $name.\n".
"Here is the message:\n $message".
?>
</body>
</html>
 

Dingus

Thread Starter
Joined
Apr 21, 2002
Messages
1,191
Hi SpywareDr. I installed WAMP a while ago, whch has PHP in it. I assumed it would work ok but have never checked it as PHP I know very little of PHP.

colinsp I'll give that a try.

Cheers for now
 

Dingus

Thread Starter
Joined
Apr 21, 2002
Messages
1,191
Boy is this PHP is blowing my mind.
I restarted my attempts to get my contact form working.
When I fill out the form and hit submit I get the error page. "OOPS"

My html, which works fine, I think, is:

<div class="email">
<form action="/EmailForm/action_page.php">

<label for="fname">First Name</label>
<input type="text" id="name" name="name" placeholder="Your first name..">

<label for="lname">Last Name</label>
<input type="text" id="lname" name="lastname" placeholder="Your last name..">

<label for="emailadd">Email Address</label>
<input type="text" id="emailadd" name="emailadd" placeholder="Your email address..">

<label for="phone">Telephone</label>
<input type="text" id="phone" name="phone" placeholder="Your telephone number..">

<label for="message">Message</label>
<textarea id="message" name="message" placeholder="Write something.." style="height:200px"></textarea>

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

</form>
</div>

My PHP, which I've borrowed and tweeked, is:

<?php


$siteemailtosend="jonDoe@gmail.com";
$siteemailtoreceive="jonDoe@gmail.com";

if(empty($_POST['fname']) ||
empty($_POST['lname']) ||
empty($_POST['emailadd']) ||
empty($_POST['phone']) ||
empty($_POST['message']) ||
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
echo "Opps,!";
return false;
}

$name = strip_tags(htmlspecialchars($_POST['name']));
$email_address = strip_tags(htmlspecialchars($_POST['email']));
$phone = strip_tags(htmlspecialchars($_POST['phone']));
$message = strip_tags(htmlspecialchars($_POST['message']));
// Create the email and send the message
$to = $siteemailtoreceive;
$email_subject = "Website Contact From: $name";
$email_body = "You have received a new message from your website contact form.\n\r\n";
$email_body = $email_body."Here are the details:\n\r\n";
$email_body = $email_body."Name: $fname\n\r\n";
$email_body = $email_body."Last Name: $lname\n\r\n";
$email_body = $email_body."Email: $emailadd\n\r\n";
$email_body = $email_body."Phone: $phone\n\r\n";
$email_body = $email_body."Message: $message\n\n\r\n";
$headers = "From: $siteemailtosend\n";
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
return true;

if ((mail($to,$subject,$message,$headers))&&(mail($autoTo, "Thank You from ", $autoreply, 'From: jonDoe@gmail.com'))) {
header("Location: ".$goto_after_mail);
$success = "Your message has been sent. We shall reply as soon as we can";
}

?>

Please remember, my PHP knowledge can be written on a pin head.
 

Dingus

Thread Starter
Joined
Apr 21, 2002
Messages
1,191
Been a few days since my last post but finally back to this problem.
As this is my first delv into PHP I'm finding it less than easy.
I've worn my Google keys out but still can't fix this.
If anyone can see a fault in my latest try !!!!!
As per SpywareDr I changed some entries to (I think) match the form and action_page, but no luck.

<?php

ini_set('display_errors', 1);
error_reporting(E_ALL);
$siteemailtosend="jondoe@gmail.com";
$siteemailtoreceive="jondoe@gmail.com";
if(empty($_POST['fname']) ||
empty($_POST['lname']) ||
empty($_POST['email']) ||
empty($_POST['phone']) ||
empty($_POST['message']) ||
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))

{
echo nl2br ("\n\n We're really sorry, but the form doesn't seem to be working. ");
return false;
}
$fname = strip_tags(htmlspecialchars($_POST['fname']));
$lname = strip_tags(htmlspecialchars($_POST['lname']));
$email = strip_tags(htmlspecialchars($_POST['email']));
$phone = strip_tags(htmlspecialchars($_POST['phone']));
$message = strip_tags(htmlspecialchars($_POST['message']));
$to = $siteemailtoreceive;
$email_subject = "Website Contact From: $name";
$email_body = "You have received a new message from your website contact form.\n\r\n";
$email_body = $email_body."Here are the details:\n\r\n";
$email_body = $email_body."Name: $fname\n\r\n";
$email_body = $email_body."Last Name: $lname\n\r\n";
$email_body = $email_body."Email: $email\n\r\n";
$email_body = $email_body."Phone: $phone\n\r\n";
$email_body = $email_body."Message: $message\n\n\r\n";
$headers = "From: $siteemailtosend\n";
$headers .= "Reply-To: $email_address\n";
mail($to,$email_subject,$email_body,$headers);
return true;
if ((mail($to,$subject,$message,$headers))&&(mail($autoTo, "Thank You from Pine Lodge", $autoreply, 'From: jondoe@gmail.com'))) {
header("Location: ".$goto_after_mail);
$success = "Your message has been sent. We shall reply as soon as we can";
}
?>
 

colinsp

Colin
Joined
Sep 5, 2007
Messages
2,365
Strip out the validation and see if it works so try this


PHP:
<?php

ini_set('display_errors', 1);
error_reporting(E_ALL);
$siteemailtosend="jondoe@gmail.com";
$siteemailtoreceive="jondoe@gmail.com";

$fname = strip_tags(htmlspecialchars($_POST['fname']));
$lname = strip_tags(htmlspecialchars($_POST['lname']));
$email = strip_tags(htmlspecialchars($_POST['email']));
$phone = strip_tags(htmlspecialchars($_POST['phone']));
$message = strip_tags(htmlspecialchars($_POST['message']));
$to = $siteemailtoreceive;
$email_subject = "Website Contact From: $name";
$email_body = "You have received a new message from your website contact form.\n\r\n";
$email_body = $email_body."Here are the details:\n\r\n";
$email_body = $email_body."Name: $fname\n\r\n";
$email_body = $email_body."Last Name: $lname\n\r\n";
$email_body = $email_body."Email: $email\n\r\n";
$email_body = $email_body."Phone: $phone\n\r\n";
$email_body = $email_body."Message: $message\n\n\r\n";
$headers = "From: $siteemailtosend\n";
$headers .= "Reply-To: $email_address\n";
mail($to,$email_subject,$email_body,$headers);
return true;
if ((mail($to,$subject,$message,$headers))&&(mail($autoTo, "Thank You from Pine Lodge", $autoreply, 'From: jondoe@gmail.com'))) {
header("Location: ".$goto_after_mail);
$success = "Your message has been sent. We shall reply as soon as we can";
}
?>
If this works then the problem is narrowed down
 

Dingus

Thread Starter
Joined
Apr 21, 2002
Messages
1,191
Hi Colin. Worse than before.
All seems to be related to:

$fname = strip_tags(htmlspecialchars($_POST['fname'])); THIS IS LINE 10
$lname = strip_tags(htmlspecialchars($_POST['lname']));
$email = strip_tags(htmlspecialchars($_POST['email']));
$phone = strip_tags(htmlspecialchars($_POST['phone']));
$message = strip_tags(htmlspecialchars($_POST['message']));
$to = $siteemailtoreceive;
$email_subject = "Website Contact From: $name";

screen_2021-04-23 10.08.05.jpg
 

colinsp

Colin
Joined
Sep 5, 2007
Messages
2,365
Actually its not it tells us what the problem is. None of your inputs have values. So in fact the validation code that I stripped out was doing what it should, saying that those input variables were empty. So the issue is with your input form not this php.
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Members online

Top