The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> PHP Development
|
HTML form to email
Discuss HTML form to email in the PHP Development forum on Dev Shed. HTML form to email PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

February 10th, 2013, 04:47 PM
|
|
Registered User
|
|
Join Date: Sep 2012
Posts: 22
Time spent in forums: 3 h 20 m
Reputation Power: 0
|
|
|
HTML form to email
I've been using a form I found online for a website in order to allow customers to contact the company by filling in the form and clicking submit.
This form worked perfectly before however I've recently been re-writing the site into HTML5 and since I did this for the php file submitting the form no longer works.
When I submit the form I get the following error:
Parse error: syntax error, unexpected $end in /home/fhlinux203/d/designercurtains.biz/user/htdocs/flex/send_form_email.php on line 179.
The file is located at www.designercurtains.biz/flex/send_form_email.php and the form is located at www.designercurtains.biz/flex/contact.html
Your help is greatly appreciated!
|

February 10th, 2013, 05:52 PM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
|
The error is in the code (you're probably missing a }) but we can't help much if we can't see it.
|

February 10th, 2013, 05:58 PM
|
|
Registered User
|
|
Join Date: Sep 2012
Posts: 22
Time spent in forums: 3 h 20 m
Reputation Power: 0
|
|
How's this...
PHP Code:
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "sue@designercurtains.biz";
$email_subject = "Designer Curtains Online Contact Form";
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['first_name']) ||
!isset($_POST['last_name']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['comments'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$email_from = $_POST['email']; // not required
$telephone = $_POST['telephone']; // not required
$comments = $_POST['comments']; // 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.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "First Name: ".clean_string($first_name)."\n";
$email_message .= "Last Name: ".clean_string($last_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "Comments: ".clean_string($comments)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>
|

February 10th, 2013, 08:52 PM
|
 |
pollyanna
|
|
Join Date: Jul 2012
Location: Germany
|
|
|
Hi,
there's no closing brace for the "if" statement.
Use an IDE like Netbeans or Eclipse to avoid errors like that.
|

February 11th, 2013, 01:19 AM
|
|
Registered User
|
|
Join Date: Sep 2012
Posts: 22
Time spent in forums: 3 h 20 m
Reputation Power: 0
|
|
|
Sorry I have no understanding whatsoever of PHP - still trying to conquer HTML. Where should the closing brack go?
|

February 11th, 2013, 04:14 AM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
It's the closing brace to
PHP Code:
if(isset($_POST['email'])) {
So where do you think it should go?
|

February 11th, 2013, 05:36 AM
|
|
Registered User
|
|
Join Date: Feb 2013
Posts: 9
Time spent in forums: 1 h 47 sec
Reputation Power: 0
|
|
|
Right at the very end before the ?> you should put a closing "}" brace.
Using a decent editor can avoid these errors like has been mentioned.
Take care,
Leon.
|

February 11th, 2013, 11:57 AM
|
|
Registered User
|
|
Join Date: Sep 2012
Posts: 22
Time spent in forums: 3 h 20 m
Reputation Power: 0
|
|
Quote: | Originally Posted by revillwebdesign Right at the very end before the ?> you should put a closing "}" brace.
Using a decent editor can avoid these errors like has been mentioned.
Take care,
Leon. |
Excellent, that's got it working again. Strange as it worked before and I just copied and pasted that extract of code over from the previous version of the website.
No matter, thanks for the help. As ever Devshed is an invaluable resource for annoying newbies like myself. I promise to research php when I'm more settled with HTML.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|