/    Sign up×
Community /Pin to ProfileBookmark

I am looking for PHP contact form for this template

I am looking for PHP contact form [URL=”http://w3layouts.com/demos/sitename/web/contact.html”]for this template[/URL]. It will also include code for a redirect link to a Thank you page. The redirecting code I have is from an older mailing form, but the mailing form doesn’t work for the new template.

[code=php]
timeOut = “0001”;

newSite = “thank_you.html”;

function timer() { self.setTimeout(“self.location.href = newSite;”,timeOut); }
[/code]

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@ginerjmAug 12.2014 — "For this template."

???
Copy linkTweet thisAlerts:
@jamesx521authorAug 12.2014 — [I]ginerjm[/I], if you scroll down on the link I provided it shows a google map, then beneath that are fields for [I]Name[/I], [I]Email[/I], [I]Subject[/I], and [I]Message[/I]. I assume I would use PHP code for the action: action="contact.php", and that's what I'm looking for.
Copy linkTweet thisAlerts:
@ginerjmAug 12.2014 — This forum is for people to show code for which they have a problem. Not to take us to who knows where for spam, viruses or whatever harm idle minds have in store for us. That said, I didn't see a link in your message until you just now told me to look for one.

A little more explanation about what problem you are having would be in order. Unless you are asking us to write your code for you, which we won't do.

PS - Why not just write your own contact form? A pretty basic thing to do, whether you're new to php or not.
Copy linkTweet thisAlerts:
@Kevin2Aug 12.2014 — See next. Gaaack.
Copy linkTweet thisAlerts:
@Kevin2Aug 12.2014 — In defense of ginerjm: I didn't see the link either, but after knowing one was there I clicked on it, come what may ?. See below.

In defense of OP: It is very difficult to tell the difference between 'standard text' and text that is a link. The font-weight, color, etc. in this forum's CSS make it almost impossible to differentiate between them. Unfortunately, one must hang around here a few months to know that when you need to post a link it's better to just paste the URL rather than highlight/[click link button]/paste URL.

Anyway, to the OP: start here:

http://validator.w3.org/check?uri=http%3A%2F%2Fw3layouts.com%2Fdemos%2Fsitename%2Fweb%2Fcontact.html&charset=%28detect+automatically%29&doctype=Inline&group=0
Copy linkTweet thisAlerts:
@jamesx521authorAug 13.2014 — [I]ginerjm[/I], I'm actually not a developer, so this stuff isn't easy for me. I can edit the code little bit here and there, but I mostly copy and paste. [I]Kevin2[/I], the validator is looking at the HTML of the page, and the PHP is my concern.

This is the HTML action calling for the PHP:

[code=php]
<form method="post" action="contact.php">
<div class="contact-to">
<input type="text" class="text" value="Name..." onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Name...';}">
<input type="text" class="text" value="Email..." onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Email...';}" style="margin-left: 10px">
<input type="text" class="text" value="Subject..." onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Subject...';}" style="margin-left: 10px">
</div>
<div class="text2">
<textarea value="Message:" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Message';}">Message..</textarea>
</div>
<div>
<a href="thank_you.html" class="submit">Submit</a>
</div>
</form>
[/code]


And this is the PHP that I have:

[code=php]


<?php

if(isset($_POST['email'])) {



// EDIT THE 2 LINES BELOW AS REQUIRED

$email_to = "email address here";

$email_subject = "Your email subject line";





function died($error) {

// your error code can go here

echo "We are very sorry, but there were error(s) found with the form you submitted. ";

echo "These errors appear below.<br /><br />";

echo $error."<br /><br />";

echo "Please go back and fix these errors.<br /><br />";

die();

}



// validation expected data exists

if(!isset($_POST['Name...']) ||

!isset($_POST['Email...']) ||

!isset($_POST['Subject...']) ||

!isset($_POST['Message:']) ||

<!--

!isset($_POST['Message:'])) { -->

died('We are sorry, but there appears to be a problem with the form you submitted.');

}



$first_name = $_POST['Name...']; // required

$last_name = $_POST['Email...']; // required

$email_from = $_POST['Subject...']; // required

$comments = $_POST['Message:']; // required



$error_message = "";

$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+.[A-Za-z]{2,4}$/';

if(!preg_match($email_exp,$email_from)) {

$error_message .= 'The Email Address you entered does not appear to be valid.<br />';

}

$string_exp = "/^[A-Za-z .'-]+$/";

if(!preg_match($string_exp,$first_name)) {

$error_message .= 'The First Name you entered does not appear to be valid.<br />';

}

if(!preg_match($string_exp,$last_name)) {

$error_message .= 'The Last Name you entered does not appear to be valid.<br />';

}

if(strlen($comments) < 2) {

$error_message .= 'The Comments you entered do not appear to be valid.<br />';

}

if(strlen($error_message) > 0) {

died($error_message);

}

$email_message = "Form details below.nn";



function clean_string($string) {

$bad = array("content-type","bcc:","to:","cc:","href");

return str_replace($bad,"",$string);

}



$email_message .= "Name: ".clean_string($Name...)."n";

$email_message .= "Email: ".clean_string($Email...)."n";

$email_message .= "Subject: ".clean_string($Subject...)."n";

$email_message .= "Message: ".clean_string($Message:)."n";





// create email headers

$headers = 'From: '.$email_from."rn".

'Reply-To: '.$email_from."rn" .

'X-Mailer: PHP/' . phpversion();

@mail($email_to, $email_subject, $email_message, $headers);

?>



<!-- include your own success html here -->



Thank you for contacting us. We will be in touch with you very soon.



<?php

}

?>
[/code]


I also see that the HTML is calling for a Thank You page, but the PHP code toward the end has its own Thank you message that probably should appear without launching the Thank you HTML page? So, at this point I probably shouldn't even have a Thank You HTML page if the PHP is going to show this message... and where does it show it?
×

Success!

Help @jamesx521 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...