I have a contact from that allows users to add an attachment but the email I receive shows Array where the image id should be.
Form details below.
First Name: gffffffffffffffffffffffffffffffffffffffffffffff
Last Name: williams
Email: jessie747williams#gmail.com
Subject: hello
Image: Array (HERE) shousd show the image like apple.jpg
Comments: fd
//Settings
$max_allowed_file_size = 100; // size in KB
$allowed_extensions = array("jpg", "jpeg", "gif", "bmp");
//Validations
if($size_of_uploaded_file > $max_allowed_file_size )
{
$errors .= "\n Size of file should be less than $max_allowed_file_size";
}
//------ Validate the file extension -----
$allowed_ext = false;
for($i=0; $i<sizeof($allowed_extensions); $i++)
{
if(strcasecmp($allowed_extensions[$i],$type_of_uploaded_file) == 0)
{
$allowed_ext = true;
}
}
if(!$allowed_ext)
{
$errors .= "\n The uploaded file is not supported file type. ".
" Only the following file types are supported: ".implode(',',$allowed_extensions);
}
if(!empty($_FILES['uploaded_file']))
{
$path = "uploads/";
$path = $path . basename( $_FILES['uploaded_file']['name']);
if(move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $path)) {
header("Location: https://www.website.com/thank-you-image/");
} else{
echo "There was an error uploading the file, please try again!";
}
}
?>
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "xxx#gmail.com";
$email_subject = "Add my image to xxx";
header("Location: https://www.website.com/thank-you-image/");
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['subject']) ||
!isset($_POST['email']) ||
!isset($_FILES['uploaded_file']) ||
!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']; // required
$subject = $_POST['subject']; // required
$uploaded_file = $_FILES['uploaded_file']; // 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(!preg_match($string_exp,$subject)) {
$error_message .= 'The Subject 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 .= "Subject: ".clean_string($subject)."\n";
$email_message .= "Image: ".clean_string($uploaded_file)."\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);
?>
<!-- include your own success html here -->
Thank you for contacting us. We will be in touch with you very soon.
So change
"Image: ".clean_string($uploaded_file)."\n";
to
"Image: ".clean_string($uploaded_file['name'])."\n";
Update:
Also, add <script> and </script> to your $bad variable in clean_string() function.
$bad = array("content-type","bcc:","to:","cc:","href","<script>","</script>");
Although email service providers strip Javascript code, but just an extra security measure.
Simply change:
$uploaded_file = $_FILES['uploaded_file'];
to
$uploaded_file = $_FILES['uploaded_file']['name'];
Related
I am trying to create a form for my website which once submitted will be converted to PDF and them emailed to myself (webmaster).
I appreciate that I cannot complete the action purely with JQuery/Javascript, I will need to use PHP to send the email.
The Javascript to convert the HTML to PDF
var doc = new jsPDF();
var specialElementHandlers = {
'#editor': function (element, renderer) {
return true;
}
};
$('#submitformz').click(function () {
doc.fromHTML($('#content').html(), 15, 15, {
'width': 190,
'elementHandlers': specialElementHandlers
});
doc.save('sample-page.pdf');
});
The problem I have with the above is that it converts to PDF and then downloads on the users computer.
Ideally I would like to convert the 'doc.save' so that it ties in with the PHP to email the document
the PHP:
if(isset($_POST['email'])) {
$email_to = "webmaster#website.com";
$email_subject = "Your email subject line";
function died($error) {
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();
}
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']; // 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);
Or... Is there any way that I could ammend the Javascript so that instead of the file downloading on the customers computer, that it, instead, downloads into the media library on my websites backend?
If I`ve understood you currently, you should get data from client and front then in back-end with php create PDF (you can use wkhtmltopdf to convert a HTML(generated by data in back-end) to PDF) then send this PDF file by email.
I have HTML and PHP code for contact form. When someone type characters like this: š, đ, ž, č, and ć (UTF-8) characters, script reports few errors.
1. How can I add UTF-8 input in $first_name and $last_name input forms?
Next problem is, message of error or success is poping up by Java Script pop up. If I type in name box "šđžčć" and in last name box "šđžčć" script is reprting three mesages:
Wrong name
Wrong last name
Please try again (not exactly like this but some message)
And that means - three pop up windows! You get one - you close it, then second - close it too, etc etc, and it's frustrating. My secong question:
2. How can I rewrite this PHP and put all messages and errors in one function/value/message and make just one pop up says: Wrong name, last name, i love you etc.
PHP code:
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "you#yourdomain.com";
$email_subject = "Your email subject line";
function died($error) {
// your error code can go here
echo "<script type='text/javascript'>alert('error')</script>";
echo "<script type='text/javascript'>alert('these errors apears below')</script>";
echo $error."<br /><br />";
echo "<script type='text/javascript'>alert('please fix errors')</script>";
die();
}
// validation expected data exists
if(!isset($_POST['first_name']) ||
!isset($_POST['last_name']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['comments'])) {
died(<script type='text/javascript'>alert('Submitted successfully!')</script>');
}
$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$email_from = $_POST['email']; // 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 .= '<script type='text/javascript'>alert('wrong email !')</script>';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$first_name)) {
$error_message .= '<script type='text/javascript'>alert('invalid firs name')</script>';
}
if(!preg_match($string_exp,$last_name)) {
$error_message .= '<script type='text/javascript'>alert('invalid last name')</script>';
}
if(strlen($comments) < 2) {
$error_message .= '<script type='text/javascript'>alert('invalid message')</script>';
}
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);
?>
<!-- include your own success html here -->
echo "<script type='text/javascript'>alert('Submitted successfully!')</script>"
<?php
}
?>
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = 'name <name#domain.com>, name <name#domain.com>,name <name#domain.com>';
$email_subject = "Enquiry for you";
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']; // 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);
?>
<!-- include your own success html here -->
Thank you for contacting us. We will be in touch with you very soon.
<?php
}
?>
You forgot a space.
Change:
$email_to = 'name <name#domain.com>, name <name#domain.com>,name <name#domain.com>';
To:
$email_to = 'name <name#domain.com>, name <name#domain.com>, name <name#domain.com>';
I would like to keep the mail.php script separate from the thank you page and have it redirect there after the script has run. My following script is causing an error - headers already sent...
What do I need to change to get the header call to work correctly?
<?php
session_start();
if(isset($_SESSION['captcha_value']) && isset($_POST['text3'])){
if($_SESSION['captcha_value'] != $_POST['text3']){
echo "invalid captcha";
die();
}
}else{
echo "invalid captcha";
die();
}
?>
<?php require_once('../inc/header-scripts.php'); ?>
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "me#mysite.com";
$email_subject = "NEW MESSAGE";
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['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
$email_from = $_POST['email']; // 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(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 = "";
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 .= "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);
?>
<!-- include your own success html here -->
<?php
}
?>
<?php
header('location: thank-you.php');
?>
You have a lot of extra space, along with an HTML comment. Take out all but the opening and closing PHP braces, and remove the HTML comment line. Be aware that if the captcha fails, it's going to stay on that page without redirecting. You might want to save the error somehow ($_SESSION or $_GET variables) and redirect to the previous page.
<?php
session_start();
if(isset($_SESSION['captcha_value']) && isset($_POST['text3'])){
if($_SESSION['captcha_value'] != $_POST['text3']){
echo "invalid captcha";
die();
}
}else{
echo "invalid captcha";
die();
}
require_once('../inc/header-scripts.php');
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "me#mysite.com";
$email_subject = "NEW MESSAGE";
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['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
$email_from = $_POST['email']; // 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(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 = "";
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 .= "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);
}
header('location: thank-you.php');
?>
I'm creating a basic contact form with a few required fields and a required selection from a drop-down menu. The fill-in fields are working correctly, however the drop-down menu selection requirement is causing a parse error.
I commented out any instances of the drop-down menu requirement to find that the error is gone. So the error has something to do with the drop-down menu selection. According to the error logs, the problem is in line 49. I tried rewriting that line a few times without much success.
Is the error caused by something specifically in line 49 or is elsewhere in my syntax?
This is my first time writing PHP, so any help is greatly appreciated.
<?php
if(isset($_POST['email'])) {
// EMAIL and SUBJECT
$email_to = "xxx#xxx.com";
$email_subject = "Test Form Dev";
function died($error) {
// ERROR CODE
echo "We apologize for the inconvenience, but there were error(s) found with your form submission. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and correct the error(s).<br /><br />";
die();
}
// VALIDATION EXPECTED DATA EXISTS
if(!isset($_POST['first_name']) ||
!isset($_POST['last_name']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['inquiry']) ||
!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']; // REQUIRED
$telephone = $_POST['telephone']; // NOT REQUIRED
$inquiry_type = $_POST['inquiry']; // 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 />';
}
$inquiry_exp = 'Charter, Media, Broker,'; // drop-down menu options
if(strlen($inquiry) < 1) {
$error_message .= 'Please select inquiry type.<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 .= "Inquiry Type: ".clean_string($inquiry)."\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);
?>
<!-- RETURN MESSAGE (HTML): SUCCESSFUL FORM SUBMISSION -->
<p>Thank-you message goes here.</p>
<?php
}
die();
?>
Edit: I'm building this form in a MAMP environment. I've read elsewhere that I need to create an htaccess file, but is that necessary for a local dev?
Edit 2: After looking around other forums, I learned that I have to break down the dropdown menu items individually in PHP. I got that accomplished, but am still getting Parse:syntax errors on line 98 (the last line) stating "unexpected $end". However, I cannot get the menu selection to populate in the generated email nor figure out what specifically is causing the error. I originally fixed my code according to the error log without success.
Here's my updated code:
<?php
if(isset($_POST['email'])) {
// EMAIL and SUBJECT
$email_to = "xxx#xxx.com";
$email_subject = "XXX";
function died($error) {
// ERROR CODE
echo "We apologize for the inconvenience, but there were error(s) found with your form submission. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and correct the error(s).<br /><br />";
die();
}
// VALIDATION EXPECTED DATA EXISTS
if(!isset($_POST['first_name']) ||
!isset($_POST['last_name']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['inquiry']) ||
!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']; // REQUIRED
$telephone = $_POST['telephone']; // NOT REQUIRED
$comments = $_POST['comments']; // REQUIRED
$inquiry = $_POST['inquiry'];
if( empty( $inquiry ) || $inquiry == "null" )
// If there isn't a value for the dropdown, or they've selected the option
// that reads "Please select one" then return an error
die( "Please select your reason for inquiring on the drop-down menu." );
switch( $inquiry ){
case "Broker" : die(); break;
case "Press" : die(); break;
case "Charter" : die(); break;
default : die();
}
}
$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 .= "Inquiry Type: ".clean_string($inquiry)."\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);
?>
<!-- place your own success html below -->
Thank you for contacting us. We will be in touch with you very soon.
<?php
}
die();
?>
Can anyone provide any insight to what's causing the form to error out?
CHange if(strlen($inquiry) < 1){ ... on line 49 to if(strlen($inquiry_type) < 1)
Also change clean_string($inquiry) to clean_string($inquiry_type) on line 69
You haven't declared a $inquiry variable so the following lines will report errors:
if(strlen($inquiry) < 1) {
$email_message .= "Inquiry Type: ".clean_string($inquiry)."\n";
You do have a $inquiry_type variable so this is probably a typo.