Difficulty connecting a contact form using PHP - php

I've tried multiple different ways to set up a contact form and connect it to an email address using PHP. This is my first time using PHP, however I know I've written the .php form correctly.
Whenever I send the form, I get redirected to an "Error 405" page.
I've Googled for a few hours, and some websites give confusing instructions about downloading PHP (which I have tried about 5 times with no success), others say that VS Code on Mac should already be able to use PHP.
I'll leave my HTML and PHP forms below (I've tried two different PHP forms with no success).
It is implied that this should be a very easy process, simply connect the HTML to PHP via "action: mail.php" attribute in the form tag, and that should be everything. Yet I have scoured the internet and have had no luck so far... Any help would be appreciated!
(I'll leave the code below, first is HTML and second/third are the two different PHP forms I have tried).
The link to my Github is here as well: "https://github.com/cjmaret/abt-website"
<form class="contact-form__form-section" action="mail.php" method="POST" accept-charset="UTF-8">
<h2 class="contact-form__form-section__title">Get In Touch</h2>
<p class="contact-form__form-section__subtitle">Fill out the form or call ###-###-#### to request an
estimate or more information. We look forward to assisting you!</p>
<fieldset class="fieldset">
<select class="input input_select" id="dropdown" name="dropdown" required>
<option value>Subject*</option>
<option value="accounts-receivable">Accounts Receievable</option>
<option value="accounts-payable">Accounts Payable</option>
<option value="human-resources">Human Resources</option>
<option value="quotes-estimates">Quotes/Estimates</option>
<option value="w9-certificates">W9/Certificates of Insurance</option>
<option value="careers">Careers</option>
<option value="general-feedback">General Feedback</option>
<option value="request-service">Request Service</option>
</select>
<div class="input">
<input class="text-input" type="text" name="name" placeholder="Name*" required>
</div>
<div class="input">
<input class="text-input" type="text" name="company" placeholder="Company">
</div>
<div class="input">
<input class="text-input" type="email" name="email" placeholder="Email*" required>
</div>
<div class="input">
<input class="text-input" type="tel" name="phone" placeholder="Phone">
</div>
<div class="input">
<textarea class="textarea" type="text" name="message" placeholder="How Can We Help?"></textarea>
</div>
<div class="g-recaptcha" data-sitekey="#########################"></div>
<button type="submit" class="button-primary button-primary_place_contact-form">
<p class="button-primary__text button-primary__text_place_contact-form">Get Started</p>
</button>
</fieldset>
</form>
<?php
if (isset($_POST['Email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "cjmaret#gmail.com";
$email_subject = "New form submissions";
function problem($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();
}
// validation expected data exists
if (
!isset($_POST['Name']) ||
!isset($_POST['Email']) ||
!isset($_POST['Message'])
) {
problem('We are sorry, but there appears to be a problem with the form you submitted.');
}
$name = $_POST['Name']; // required
$email = $_POST['Email']; // required
$message = $_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)) {
$error_message .= 'The Email address you entered does not appear to be valid.<br>';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if (!preg_match($string_exp, $name)) {
$error_message .= 'The Name you entered does not appear to be valid.<br>';
}
if (strlen($message) < 2) {
$error_message .= 'The Message you entered do not appear to be valid.<br>';
}
if (strlen($error_message) > 0) {
problem($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 .= "Name: " . clean_string($name) . "\n";
$email_message .= "Email: " . clean_string($email) . "\n";
$email_message .= "Message: " . clean_string($message) . "\n";
// create email headers
$headers = 'From: ' . $email . "\r\n" .
'Reply-To: ' . $email . "\r\n" .
'X-Mailer: PHP/' . phpversion();
#mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- include your success message below -->
Thank you for contacting us. We will be in touch with you very soon.
<?php
}
?>
#!/usr/bin/php
<?php
$name = $_POST['name'];
$company = $_POST['company'];
$email = $_POST['email'];
$dropdown = $_POST['dropdown'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$formcontent="From: $name \n Phone: $phone \n Company: $company \n Email: $email \n Subject: $dropdown \n Message: $message";
$recipient = "cjmaret#gmail.com";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!";
?>

Related

Contact Form, sending an email is just downloading my PHP file

I'm having a weird error that I cannot figure out with a PHP file, I've never touched PHP and I am trying to use it to send a Name, Email Address, and a message back to me from a website, but for some reason, the code I wrote is just downloading the PHP file instead, can anyone else see where I may be going wrong here:
HTML
<div class="modal-body">
<div class="container"> <!-- TODO add in contact form -->
<form action="form-to-action.php">
<label for="fname">Name</label>
<input type="text" id="Name" name="Name" placeholder="Name">
<label for="lname">Email Address</label>
<input type="text" id="Email" name="Email" placeholder="Email Address">
<br>
<label for="subject">How can we Help?</label>
<textarea id="Message" name="Message" placeholder="Write something.." style="height:200px"></textarea>
<input type="submit" value="Send"id="contactBtnModal"style="text-decoration: none;" >
</form>
</div>
</div>
PHP:
<?php
if (isset($_POST['Email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "testingemail#gmail.com";
$email_subject = "Testing";
function problem($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();
}
// validation expected data exists
if (
!isset($_POST['Name']) ||
!isset($_POST['Email']) ||
!isset($_POST['Message'])
) {
problem('We are sorry, but there appears to be a problem with the form you submitted.');
}
$name = $_POST['Name']; // required
$email = $_POST['Email']; // required
$message = $_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)) {
$error_message .= 'The Email address you entered does not appear to be valid.<br>';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if (!preg_match($string_exp, $name)) {
$error_message .= 'The Name you entered does not appear to be valid.<br>';
}
if (strlen($message) < 2) {
$error_message .= 'The Message you entered do not appear to be valid.<br>';
}
if (strlen($error_message) > 0) {
problem($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 .= "Name: " . clean_string($name) . "\n";
$email_message .= "Email: " . clean_string($email) . "\n";
$email_message .= "Message: " . clean_string($message) . "\n";
// create email headers
$headers = 'From: ' . $email . "\r\n" .
'Reply-To: ' . $email . "\r\n" .
'X-Mailer: PHP/' . phpversion();
#mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- include your success message below -->
Thank you for contacting us. We will be in touch with you very soon.
<?php
}
?>
Are you installed a PHP server in your Computer?
If not, download WAMP and try again, you need access the page via http://localhost, and not via file://path_to_document in your web navigator.
Or run the script in a web server.

PHP create Form to CSV and Send to email as attachment

I am creating a webpage that has a form, and in that form I need to save it as csv and I need it to be sent to an email as an attachment file, how do I do that?
First how can I output all of the inputs to csv, then save it as csv file and automatically attach it to email.
Below is the code I've tried :
PHP
<?php
// define variables and set to empty values
$nameErr = $emailErr = $countryErr = $confirmErr = "";
function clean_text($string)
{
$string = trim($string);
$string = stripslashes($string);
$string = htmlspecialchars($string);
return $string;
}
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "sample#email";
$email_subject = "Form Submission";
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 />";
exit();
}
// validation expected data exists
if(!isset($_POST['name']) ||
!isset($_POST['email']) ||
!isset($_POST['country']) ||
!isset($_POST['confirm_email'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$name = $_POST['name']; // required
$email_from = $_POST['email']; // required
$country = $_POST['country']; // not required
$confirm_email = $_POST['confirm_email']; // 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,$name)) {
$error_message .= 'The Name you entered does not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Subsciber Details Information.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Full Name: ".clean_string($name)."\n";
$email_message .= "Country: ".clean_string($country)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Confirmed Email: ".clean_string($confirm_email)."\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);
/*Autoreply Sender Name*/
$headerss = "FROM: APSR2020 <2020#coac.co.jp>\r\n";
/* Prepare autoresponder subject */
$respond_subject = "Sign-up for APSR 2020 Mailing List Completed";
/* Prepare autoresponder message */
$respond_message = "Thank you for your interest in sign-up for our mailing list.
We will keep you updated on APSR 2020.
In the case that this email is unexpected, it will be troubling, but please inquire through the given address.
Congress Secretariat of APSR 2020
subs-apsr 2020#coac.co.jp
Please keep get in touch with: https://apsr2020.jp
";
/* Send the response message using mail() function */
mail($email_from, $respond_subject, $respond_message, $headerss);
//redirect to the 'thank you' page
header('Location: thank-you-page.html');
?>
<!-- include your own success html here -->
<?php
}
?>
HTML form
<form name="contactform" method="post">
<div class="keep__me__posted">
<p>Please sign up NOW.</p>
<p class="margin__p">We will keep you updated on APSR 2020.</p>
<div class="input__form">
<label for="name">Name</label>
<input type="text" id="name" name="name" maxlength="50" size="30" value="" required>
</div>
<div class="input__form">
<label for="country">Country</label>
<input type="text" id="country" name="country" maxlength="30" size="30" value="" required>
</div>
<div class="input__form">
<label for="email">Email Address</label>
<input type="email" id="email" name="email" maxlength="80" size="30" value="" required>
</div>
<div class="input__form">
<label for="confirm_email">Confirm Email</label>
<input type="email" id="confirm_email" name="confirm_email" maxlength="30" size="30" required>
</div>
<div class="input__form submit">
<tr>
<td colspan="2" style="text-align:center">
<input type="submit" value="Subscribe" class="submit" onclick="checkEmail()">
</td>
</tr>
</div>
</div>
</form>
To write in your csv file, you can take a look at
this function :
$file = fopen('yourFile.csv', 'w');
fputcsv($file, array('this','is some', 'csv "stuff", you know.'));
fclose($file);
To send this file with the mail, I think the easier option is to use PHPMailer.
Don't really know how to use it, but you can easily find it out here. You firstly need to download and instal the package found on gitHub and then use it like this :
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
$email = new PHPMailer();
$email->SetFrom('you#example.com', 'Your Name'); //Name is optional
$email->Subject = 'Message Subject';
$email->Body = $bodytext;
$email->AddAddress( 'destinationaddress#example.com' );
$file_to_attach = 'PATH_OF_YOUR_FILE_HERE';
$email->AddAttachment( $file_to_attach , 'NameOfFile.pdf' );
return $email->Send();

Why is my PHP/HTML form not sending me data

I am trying out PHP after years of inactivity, and I thought I had it but looks like I lost the touch. Can anyone see why I might not be getting any data sent to my email address?
HTML code:
<form name="Call Back Request" id="request-call-form" action="callbackrequest.php" method="POST" novalidate="novalidate">
<div class="col-md-6">
<input id="name" type="text" placeholder="Name" name="name">
<input id="email" type="text" placeholder="Email" name="email">
</div>
<div class="col-md-6">
<input id="phone" type="text" placeholder="Phone" name="phone">
<input id="subject" type="text" placeholder="Subject" name="subject">
</div>
<div class="col-md-6">
<button type="submit" value="submit" class="thm-btn">submit now</button>
</div>
<div class="col-md-12">
<div id="success"></div>
</div>
</form>
PHP Code:
<?php
if (isset($_POST['email'])) {
$email_to = "xxxxx#xxxx.com";
$email_subject = "Call Back Request Form - Home Page | rootlayertechnologies.com.au";
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 and submit the form again.<br /><br />";
die();
}
// validation expected data exists
if (!isset($_POST['name']) || !isset($_POST['email']) || !isset($_POST['phone']) || !isset($_POST['subject'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$first_name = $_POST['name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['phone']; // not required
$comments = $_POST['subject']; // 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, $name)) {
$error_message .= 'The Name you entered does not appear to be valid.<br />';
}
if (strlen($subject) < 2) {
$error_message .= 'The Subject you entered does 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 = [
"content-type",
"bcc:",
"to:",
"cc:",
"href"
];
return str_replace($bad, "", $string);
}
$email_message .= "Name: " . clean_string($name) . "\n";
$email_message .= "Email: " . clean_string($email_from) . "\n";
$email_message .= "Phone: " . clean_string($phone) . "\n";
$email_message .= "Subject: " . clean_string($subject) . "\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 -->
<p>Thanks for contacting us. We have received your request for a call back and a friendly member of our Product Solutions team will be in touch with you soon.</p>
<?php}?>
I would begin by removing the <a> tag inside the <submit> button. I think that by clicking the link, you may be just opening the page instead of submitting the form.
Then, on the PHP code, i would confirm that $email_to is properly set. (It may seem obvious, but it's always worth confirming.)
I couldn't test the code, but i didn't find any bugs per se. (Some things could be improved, e.g. lack of filter_var and perhaps html_escape, addslashes, or strip_tags.)
This leads me to think that the problem may be at the server level. So, here are some things to consider:
From: must be an address from the same domain as the site (e.g. info#rootlayertechnologies.com.au). Keep Reply-to: as is, though.
Ensure that the SPF record is properly set. You may also want to delve into DKIM and DMARC.
Some hosting companies disable PHP mail. You may need to implement SMTP.

PHP/HTML Contact Form

I am unsure why my contact form is not working, it uses html and php but I can not for the life of me work out whatI have done wrong for it not to work. I have done weeks and weeks of research and experiments and still nothing. I would be very grateful if somebody could point me in the correct direction. Thank you, my code is below
HTML
<form method="POST" name="contactform" action="contact-form-handler.php">
<p align="center">
<label for='name'><FONT color="#FFFFFF" SIZE=2>YOUR NAME:</FONT></label>
<font color="#FFFFFF">
<input name="name" type="text">
</font></p>
<p align="center">
<font color="#FFFFFF">
<label for='telephone'><FONT SIZE=2>TELEPHONE:</FONT></label>
<input name="telephone" type="text">
</font></p>
<p align="center">
<font color="#FFFFFF">
<label for='email'><FONT SIZE=2>EMAIL:</FONT></label>
<input name="email" type="text">
<br>
</font></p>
<p align="center">
<font color="#FFFFFF">
<label for='budget'><FONT SIZE=2>BUDGET:</FONT></label>
<input name="budget" type="text" id="finish">
<br>
</font></p>
<p align="center">
<font color="#FFFFFF">
<label for='location'><FONT SIZE=2>LOCATION:</FONT></label>
<input name="location" type="text" id="location">
<br>
</font></p>
<p align="center">
<font color="#FFFFFF">
<label for='service'><FONT SIZE=2>SERVICE:</FONT></label>
<select id="service" name="service">
<option value="000">Pick Service</option>
<option>Resealing</option>
<option>Toilet Plumbing</option>
<option>Boiler Work</option>
<option>Exterior Plumbing</option>
</select>
</font></p>
<p align="center">
<font color="#FFFFFF">
<label for='message'><FONT SIZE=2>INFO:</FONT></label>
<textarea name="message"></textarea>
</font></p>
<div align="center">
<font color="#FFFFFF">
<input type="submit" value="SUBMIT">
</font></div>
</form>
PHP1 contact-form-handler
<?php
$errors = '';
$myemail = 'david#mildenhire.com';
if(empty($_POST['name']) ||
empty($_POST['telephone']) ||
empty($_POST['email']) ||
empty($_POST['budget']) ||
empty($_POST['location']) ||
empty($_POST['service']) ||
empty($_POST['message']))
{
$errors .= "\n Error: all fields are required";
}
$name = $_POST['name'];
$telephone = $_POST['telephone'];
$email_address = $_POST['email'];
$budget = $_POST['budget'];
$location = $_POST['location'];
$service= $_POST['service'];
$message = $_POST['message'];
if (!preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*#[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i",
$email_address))
{
$errors .= "\n Error: Invalid email address";
}
if( empty($errors))
{
$to = $myemail;
$email_subject = "Free Quote: $name";
$email_body = "You have received a new free quote request. ".
" Here are the details:\n Name: $name \n Telephone: $telephone \n Email: $email_address \n Budget: $budget \n Location: $location \n Service: $service \n Message: \n $message";
$headers = "From: $email_address \n";
$headers .= "Reply-To: $email_address \n";
mail($to,$email_subject,$email_body,$headers);
header('Location: thankyou.html');
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Big Smile Free Quote Request</title>
</head>
<body>
<!-- This page is displayed only if there is some error -->
<?php
echo nl2br($errors);
?>
</body>
</html>
PHP 2 contactformprocess.php
<?php
if(isset($_POST['Email_Address'])) {
include 'freecontactformsettings.php';
function died($error) {
echo "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('Sorry, there appears to be a problem with your form submission.');
}
$full_name = $_POST['first_name']; // required
$email_from = $_POST['last_name']; // required
$telephone = $_POST['email']; // required
$comments = $_POST['telephone']; // required
$antispam = $_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)==0) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
if(strlen($first_name) < 2) {
$error_message .= 'Your First Name does not appear to be valid.<br />';
}
if(strlen($last_name) < 2) {
$error_message .= 'Your Last Name does not appear to be valid.<br />';
}
if(strlen($email) < 2) {
$error_message .= 'Your E-mail does not appear to be valid.<br />';
}
if(strlen($telephone) < 2) {
$error_message .= 'Your Telephone Number 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.\r\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:");
return str_replace($bad,"",$string);
}
$email_message .= "First Name: ".clean_string($first_name)."\r\n";
$email_message .= "Last Name: ".clean_string($last_name)."\r\n";
$email_message .= "E-Mail: ".clean_string($email)."\r\n";
$email_message .= "Telephone: ".clean_string($telephone)."\r\n";
$email_message .= "Message: ".clean_string($comments)."\r\n";
$headers = 'From: '.$email."\r\n".
'Reply-To: '.$email."\r\n" .
'X-Mailer: PHP/' . phpversion();
#mail($email_to, $email_subject, $email_message, $headers);
header("Location: $thankyou");
?>
<script>location.replace('<?php echo $thankyou;?>')</script>
<?php
}
die();
?>
I know this is a fair bit to read through but it doesn't take long as it is mostly PHP Script.
I hope you can help me you wonderful people
Perhaps it is just a problem of SMTP configuration.
Since you get no error, I assume the function mail() is correctly called, but if your server is not properly configured for sending emails, you can't receive anything.
My advice would be to take a look at your webserver configuration (you're probably using something like WAMP or EasyPHP).

Email form from a website via PHP issues

I am coding a personal website and having an issue with my contact from. If you can help me find what's wrong I would really appreciate it.
The link to the website is www.tiryakicreative.com and the code for the php form is given below:
<div id="form">
<form id="ajax-contact-form" action="contact_form/send_form_email.php…
<fieldset class="info_fieldset">
<div id="note"></div>
<div id="fields">
<label>Name</label>
<input class="textbox" type="text" name="name" value="" />
<label>E-Mail</label><input class="textbox" type="text" name="email" value="" />
<label>Subject</label>
<input class="textbox" type="text" name="subject" value="" />
<label>Message</label>
<textarea class="textbox2" name="message" rows="5" cols="25"></textarea>
<label> </label><input class="button" type="image" src="send2.gif" id="submit" Value="Send Message" />
</div>
</fieldset>
</form>
</div>
</div>
Here is the php code for the given html code:
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "ian_tiryaki#hotmail.com";
$email_subject = "New Email from Website";
function died($error) {
// ERROR CODE GOES HERE
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.";
echo $error."";
echo "Please go back and fix these errors.";
die();
}
// validation expected data exists
if(!isset($_POST['name']) ||
!isset($_POST['email']) ||
!isset($_POST['subject']) ||
!isset($_POST['message'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$first_name = $_POST['name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['subject']; // not required
$comments = $_POST['message']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+#[A-Za-z0-9.-]+\.[A-Z…
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$first_name)) {
$error_message .= 'The Name you entered does not appear to be valid.';
}
if(!preg_match($string_exp,$last_name)) {
$error_message .= 'The subject you entered does not appear to be valid.';
}
if(strlen($comments) < 2) {
$error_message .= 'The message you entered do not appear to be valid.';
}
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:",…
return str_replace($bad,"",$string);
}
$email_message .= "First Name: ".clean_string($first_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Subject: ".clean_string($telephone)."\n";
$email_message .= "Message: ".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 success html here -->
Thank you for contacting us. We will be in touch with you very soon.
<?php
}
?>
Are you receiving the emails after the user sends the email?
Try adding
error_reporting(E_ALL);
to the top of your script.
You could also try removing the # from the mail command
mail($email_to, $email_subject, $email_message, $headers);
As this will be suppressing any errors that is being generated.
It could be something as simple as the PHP mail function having additional headers disabled (some hosts do this for security reasons) in which case the mail function will fail.
set this is in your action form ...
and you will definately get mail from here..
and although there is an error you may be use use below code for send mail using php without declare a variable...
like
$email_to=$_POST['email'];
$email_subject=$_POST['subject'];
$email_message=$_POST['message'];
$headers=$_POST['title'];
mail('$email_to', '$email_subject', '$email_message', '$headers');
otherwise
use below code for send mail
mail('$_POST['email']','$_POST['subject']','$_POST['message']','$_POST['title']');

Categories