This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 6 years ago.
My php form has stopped sending through new enquiries to my email ever since I updated it to submit to self.
I've tried both an email address I use with my website host and a gmail address. Any suggestions will be much appreciated.
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
<div class="col-lg-12">
<h2>Contact us!</h2>
<form class="form-horizontal" name="enquiryform" method="post" action="">
<div class="form-group-lg">
<label class="control-label col-xs-4" for="name">Name *</label>
<div class="col-xs-8">
<input type="text" class="form-control" id="name" placeholder="First name" name="name" required>
</div>
</div>
<div class="form-group-lg">
<label class="control-label col-xs-4" for="surname">Surname</label>
<div class="col-xs-8">
<input type="text" class="form-control" id="surname" placeholder="Last name" name="surname">
</div>
</div>
<div class="form-group-lg">
<label class="control-label col-xs-4" for="email">Email *</label>
<div class="col-xs-8">
<input type="email" class="form-control" id="email" placeholder="you#example.com" name="email" required>
</div>
</div>
<div class="form-group-lg">
<label class="control-label col-xs-4" for="mobile">Mobile</label>
<div class="col-xs-8">
<input type="tel" class="form-control" id="mobile" placeholder="Phone number" name="mobile">
</div>
</div>
<div class="form-group-lg">
<label class="control-label col-xs-4" for="message" name="message">Enquiry:</label>
<textarea class="form-control" id="message" rows="6" name="message" placeholder="Your message." required></textarea>
<div class="form-group">
<div class="col-xs-12">
<input type="submit" class="btn btn-primary" value="Submit">
</div>
</div>
</div>
</form>
</div>
</div>
<p></p>
<?php
$name = $_POST['name'];
$surname = $_POST['surname'];
$email = $_POST['email'];
$mobile = $_POST['mobile'];
$message = $_POST['message'];
$formcontent="From: $email \n $name \n $surname \n $mobile \n Message: $message";
$recipient = "me#host.com";
$subject = "Enquiry";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
?>
</body>
The syntax of php email sending function is:
bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )
mail($admin_email, "$first_name", $last_name, "$telephone", "$comments", "From:" . $email);
But in your case your parameter do not match with the required parameter.
Follow the syntax and try again.
You used extra parameters passed in your mail function.. I change some of your code look this.
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
<?php
$action=$_REQUEST['action'];
if ($action=="")
{
?>
<div class="col-lg-12">
<h2>Contact us!</h2>
<form class="form-horizontal" name="enquiryform" method="post" action="">
<div class="form-group-lg">
<label class="control-label col-xs-4" for="first_name">Name *</label>
<div class="col-xs-8">
<input type="text" class="form-control" id="name" placeholder="First name" name="name" required>
</div>
</div>
<div class="form-group-lg">
<label class="control-label col-xs-4" for="surname">Surname</label>
<div class="col-xs-8">
<input type="text" class="form-control" id="surname" placeholder="Last name" name="surname">
</div>
</div>
<div class="form-group-lg">
<label class="control-label col-xs-4" for="inputEmail">Email *</label>
<div class="col-xs-8">
<input type="email" class="form-control" id="inputEmail" placeholder="you#example.com" name="email" required>
</div>
</div>
<div class="form-group-lg">
<label class="control-label col-xs-4" for="telephone">Mobile</label>
<div class="col-xs-8">
<input type="tel" class="form-control" id="Mobile" placeholder="Phone number" name="mobile">
</div>
</div>
<div class="form-group-lg">
<label class="control-label col-xs-4" for="exampleTextarea" name="message">Enquiry:</label>
<textarea class="form-control" id="exampleTextarea" rows="6" name="message" placeholder="Your message." required></textarea>
<div class="form-group">
<div class="col-xs-12">
<input type="submit" class="btn btn-primary" value="Submit">
</div>
</div>
</div>
</form>
</div>
</div>
<p></p>
<?php
}
else
{
$name = $_REQUEST['name'];
$surname = $_REQUEST['surname'];
$email = $_REQUEST['email'];
$mobile = $_REQUEST['mobile'];
$message = $_REQUEST['message'];
$formcontent="From: $email \n $name \n $surname \n $mobile \n Message: $message";
$recipient = "me#host.com";
$subject = "Enquiry";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
}
?>
</body>
</html>
If any Query comment here...
Related
I've been having trouble with PHP (new to php) to clear my form fields AFTER a successful submission. I would also like to show an alert that it was successful. Any ideas? Using javascript with the onclick listener for the submit button will not work because it clears the fields before PHP has time to send the data.
Here is my html:
<div class="col-lg-7 mt-5 mt-lg-0 d-flex align-items-strech" data-aos="fade-left">
<form id="contact-form" action="contact-form-handler.php" method="post" role="form" class="php-email-form">
<div class="form-row">
<div class="form-group col-md-6">
<label for="name">Name</label>
<input type="text" name="name" class="form-control" id="name" data-rule="minlen:4" data-msg="Please enter at least 4 characters"/>
<div class="validate"></div>
</div>
<div class="form-group col-md-6">
<label for="name">Email</label>
<input type="email" name="email" class="form-control" id="email" data-rule="email" data-msg="Please enter at valid email"/>
<div class="validate"></div>
</div>
</div>
<div class="form-group">
<label for="name">Subject</label>
<input type="text" class="form-control" name="subject" id="subject" data-rule="minlen:4" data-msg="Please enter a subject of at least 8 characters"/>
<div class="validate"></div>
</div>
<div class="form-group">
<label for="message">Message</label>
<textarea class="form-control" name="message" rows="10" data-rule="required" data-msg="Please enter a message"></textarea>
<div class="validate"></div>
</div>
<div class="text-center"><button type="submit">Send Message</button></div>
</form>
</div>
Here is my PHP:
<?php
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$email_from = "Portfolio Email";
$email_body = "Name: $name.\n".
"User Email: $visitor_email.\n".
"User Message: $message.\n";
$email_to = "email#gmail.com";
$headers = "From: $email_from \r\n";
mail($email_to, $subject, $email_body);
?>
If you do not want to use ajax, please try the following
(assuming the html is known as "form.html", and the php is "contact-form-handler.php")
The php redirection to form.html will clear the input fields (a normal behavior in web-browsers), and the javascript will show the word "successful" as an alert.
Please make further adjustment(s) according to your needs.
form.html
<div class="col-lg-7 mt-5 mt-lg-0 d-flex align-items-strech" data-aos="fade-left">
<form id="contact-form" action="contact-form-handler.php" method="post" role="form" class="php-email-form">
<div class="form-row">
<div class="form-group col-md-6">
<label for="name">Name</label>
<input type="text" name="name" class="form-control" id="name" data-rule="minlen:4" data-msg="Please enter at least 4 characters"/>
<div class="validate"></div>
</div>
<div class="form-group col-md-6">
<label for="name">Email</label>
<input type="email" name="email" class="form-control" id="email" data-rule="email" data-msg="Please enter at valid email"/>
<div class="validate"></div>
</div>
</div>
<div class="form-group">
<label for="name">Subject</label>
<input type="text" class="form-control" name="subject" id="subject" data-rule="minlen:4" data-msg="Please enter a subject of at least 8 characters"/>
<div class="validate"></div>
</div>
<div class="form-group">
<label for="message">Message</label>
<textarea class="form-control" name="message" rows="10" data-rule="required" data-msg="Please enter a message"></textarea>
<div class="validate"></div>
</div>
<div class="text-center"><button type="submit">Send Message</button></div>
</form>
</div>
<script>
function get(name){
if(name=(new RegExp('[?&]'+encodeURIComponent(name)+'=([^&]*)')).exec(location.search))
return decodeURIComponent(name[1]);
}
</script>
<script>
if (get("result")=="success")
{
alert("Successful");
}
</script>
contact-form-handler.php
<?php
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$email_from = "Portfolio Email";
$email_body = "Name: $name.\n".
"User Email: $visitor_email.\n".
"User Message: $message.\n";
$email_to = "email#gmail.com";
$headers = "From: $email_from \r\n";
mail($email_to, $subject, $email_body);
?>
<script>
window.location.href="form.html?result=success"
</script>
My bootstrap 4 form is not sending any messages, I've uploaded the index.php and contact.php files on the server and I'm not having any response. Would you be able to help me find the problem?
Landing page with simple form
<form id="#contacts" method="POST" class="form" role="form">
<div class="row">
<div class="col-md-6 form-group">
<input class="form-control" id="name" name="name"
placeholder="Podaj swoje Imię i nazwisko" type="text" required/>
</div>
<div class="col-md-6 form-group">
<input class="form-control" id="website" name="website"
placeholder="Adres strony www" type="text" required/>
</div>
<div class="col-md-6 form-group">
<input class="form-control" id="telephone" name="telephone"
placeholder="Podaj swój numer telefonu" type="text" required/>
</div>
<div class="col-md-6 form-group">
<input class="form-control" id="email" name="email"
placeholder="Podaj swój email" type="email" required/>
</div>
</div>
<textarea class="form-control" id="message" name="message" placeholder="Twoja wiadomość"
rows="4"></textarea>
<br>
<div class="row">
<div class="col-md-12 form-group">
<button class="btn btn-primary" type="submit">Wyślij</button>
</div>
</div>
</form>
contact.php
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$website = $_POST['website'];
$telephone = $_POST['telephone'];
$email_from = 'SEO';
$email_subject = 'Wiadomość kontaktowa z... '
$email_body = "Name: $name.\n".
"Email: $email.\n".
"Message: $message.\n";
"Website: $website.\n";
"Telephone: $telephone.\n";
$to = "biuro#of.pl";
$headers = "From: $email_from r\n";
$headers .= "Reply-To: $email r\n";
mail($to,$email-$email_subject,$email_body,$headers);
header("location: index.php");
?>
Your form is missing Action
<form id="#contacts" method="POST" class="form" role="form" action="contact.php">
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 4 years ago.
I'm trying to create a contact us form with PHP. The problem is that, I'm not receiving the email in my account. When the submit button is clicked it takes me to the mail.php page where a "thank you" message is shown.
The code is as shown below:
<div class="container">
<div class="col-xs-offset-2 col-xs-10 col-sm-8">
<h2>Contact Us</h2>
<form action="mail.php" method="POST" class="form-horizontal">
<div class="form-group">
<label class="control-label col-sm-2 col-xs-6" for="email">First Name:</label>
<div class="col-sm-6 col-xs-6">
<input type="text" class="form-control" id="fname" placeholder="First Name*" name="fname" required="required">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="email">Last Name:</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="lname" placeholder="last Name" name="lname" >
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="email">Email ID:</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="email" placeholder="Email Address*" name="email" required="required">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="message">Message:</label>
<div class="col-sm-6">
<textarea id="form_message" name="message" class="form-control" placeholder="Message*" rows="4" required="required" data-error="Please, leave us a message."></textarea>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</form>
</div>
The code for mail.php:
<?php
$firstname = $_POST['fname'];
$lastname = $_POST['lname'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From: $fname $lname \n Message: $message";
$recipient = "rubeena.ajeed#gmail.com";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!";
?>
Please try using SMTP ?
PHPmailler.class
Download : https://github.com/PHPMailer/PHPMailer
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 6 years ago.
I'm building a site, and am having problems with the php form. I have looked through and cannot find anything that I see as wrong. However, I am also not very proficient with PHP and have never created a form like this before. Thank you very much if you can help.
Here is the code:
PHP:
<?php
$company = $_POST['company'];
$email = $_POST['email'];
$name = $_POST['name'];
$phone = $_POST['phone'];
$numberofvehicles = $_POST['numofvehicles'];
$date= $_POST['date'];
$time = $_POST['time'];
$address = $_POST['address'];
$to = 'email#email.com';
$subject = "GPS Form Request: $company\n";
$body = "From: $name\n E-Mail: $email\n Company:\n $company Phone: $phone\n Date: $date\n Time: $time\n Address: $address\n Number of Vehicles: $numberofvehicles\n";
$headers = "From: $email" . "\r\n" .
"Reply-To: $email" . "\r\n" .
"X-Mailer: PHP/" . phpversion();
if(isset($_POST['submit']){
mail ($to, $subject, $body, $headers); //mail sends it to the SMTP server side which sends the email
echo "<p>Your message has been sent!</p>";
}
else {
echo "<p>Something went wrong, go back and try again!</p>";
}
?>
HTML:
<form id="contact-form" method="post" action="/php/email.php" role="form">
<fieldset>
<div class="messages"></div>
<div class="controls">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="company_name">Your Company's Name</label>
<input id="company_name" type="text" name="company" class="form-control" placeholder="Please enter your company's name *" required="required" data-error="Firstname is required.">
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="your_name">Your Name</label>
<input id="your_name" type="text" name="name" class="form-control" placeholder="Please enter your first and last name *" required="required" data-error="Lastname is required.">
<div class="help-block with-errors"></div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="form_email">Preferred Email</label>
<input id="form_email" type="email" name="email" class="form-control" placeholder="Please enter your preferred email *" required="required" data-error="Valid email is required.">
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="form_phone">Preferred Phone</label>
<input id="form_phone" type="tel" name="phone" class="form-control" placeholder="Please enter your preferred phone number">
<div class="help-block with-errors"></div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="vehicles_number">Number of Vehicles</label>
<input id="vehicles_number" type="text" name="numofvehicles" class="form-control" placeholder="How many vehicles for installation?">
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="install_address">Installation Address</label>
<input id="input_address" type="text" name="address" class="form-control" placeholder="What is the installation address?">
<div class="help-block with-errors"></div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="install_date">Choose a Date for Installation</label>
<input id="calendar" name="date" type="text" class="form-control" placeholder="Please choose a date for installation" >
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="install_time">Choose a Time for Installation</label>
<input id="install_time" type="time" name="phone" class="form-control" placeholder="Please choose a time for installation">
<div class="help-block with-errors"></div>
</div>
</div>
</div>
<div class="row">
</fieldset>
<fieldset>
<div class="col-md-12">
<input type="submit" id="submit" name="submit" class="btn btn-success btn-send" value="Send message">
</div>
</div>
</div>
</div>
</fieldset>
</form>
</container>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="js/bootstrap-datepicker.js"></script>
<script>
$('#calendar').datepicker({
inline: true,
firstDay: 1,
showOtherMonths: true,
dayNamesMin: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
});
</script>
</body>
</div>
You are missing a closing parenthesis bracket in your php if statement.
if(isset($_POST['submit']))
At the very end of that statement ^
I have a Bootstrap 3 form that displays the success message: "Your message has been sent" but I don't receive any emails. Not even in my spam/junk folder. It validates properly but no email is sent. Here's the PHP code. Please help!
PHP
<?php
// check if fields passed are empty
if(empty($_POST['firstname']) ||
empty($_POST['lastname']) ||
empty($_POST['address']) ||
empty($_POST['address2']) ||
empty($_POST['city']) ||
empty($_POST['state_province']) ||
empty($_POST['country']) ||
empty($_POST['zip']) ||
empty($_POST['phone']) ||
empty($_POST['email']) ||
empty($_POST['checkbox']) ||
empty($_POST['comment']) ||
{
echo "No arguments Provided!";
return false;
}
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$address = $_POST['address'];
$address2 = $_POST['address2'];
$city = $_POST['city'];
$state_province = $_POST['state_province'];
$country = $_POST['country'];
$zip = $_POST['zip'];
$phone = $_POST['phone'];
$email_address = $_POST['email'];
$checkbox = $_POST['checkbox'];
$message = $_POST['comment'];
// create email body and send it
$to = 'email#example.com'; // put your email
$email_subject = "Contact form submitted by: $firstname";
$email_body = "You have received a new message. \n\n".
"Here are the details:\n \nFirst Name: $firstname \n Last Name: $lastname\n Address: $address\n Address2: $address2\n City: $city\n State/Province: $state_province\n Country: $country\n zip: $zip\n Phone: $phone\n Email: $email_address\n Checkbox: $checkbox\n Message: \n $message";
$headers = "From: $email_address\n";
$headers = "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
return true;
?>
HTML
<form class="form-horizontal" role="form" id="ContactUs" novalidate>
<!-- First Name -->
<div class="form-group">
<label class="control-label col-md-4" for="firstname"><abbr title="Required field">*</abbr>First Name</label>
<div class="col-md-8">
<input type="text" class="form-control" id="firstname" name="firstname" placeholder="First Name" required data-validation-required-message="Please enter your first name">
<div class="help-block"></div>
</div>
</div>
<!-- Last Name -->
<div class="form-group">
<label class="control-label col-md-4" for="lastname"><abbr title="Required field">*</abbr>Last Name</label>
<div class="col-md-8">
<input type="text" class="form-control" id="lastname" name="lastname" placeholder="Last Name" required data-validation-required-message="Please enter your last name">
<div class="help-block"></div>
</div>
</div>
<!-- Address -->
<div class="form-group">
<label class="control-label col-md-4" for="address"><abbr title="Required field">*</abbr>Address</label>
<div class="col-md-8">
<input type="text" class="form-control" id="address" name="address" placeholder="Address" required data-validation-required-message="Please enter your address">
<div class="help-block"></div>
</div>
</div>
<!-- Address 2 -->
<div class="form-group">
<label class="control-label col-md-4" for="address2">Address 2</label>
<div class="col-md-8">
<input type="text" class="form-control" id="address2" name="address2" placeholder="Address 2">
</div>
</div>
<!-- City -->
<div class="form-group">
<label class="control-label col-md-4" for="city"><abbr title="Required field">*</abbr>City</label>
<div class="col-md-8">
<input type="text" class="form-control" id="city" name="city" placeholder="City" required data-validation-required-message="Please enter your city">
<div class="help-block"></div>
</div>
</div>
<!-- State/Province -->
<div class="form-group">
<label class="control-label col-md-4" for="state_province"><abbr title="Required field">*</abbr>State/Province</label>
<div class="col-md-8">
<input type="text" class="form-control" id="state_province" name="state_province" placeholder="State/Province" required data-validation-required-message="Please enter your State or Province">
<div class="help-block"></div>
</div>
</div>
<!-- Country -->
<div class="form-group">
<label class="control-label col-md-4" for="country"><abbr title="Required field">*</abbr>Country</label>
<div class="col-md-8">
<input type="text" class="form-control" id="country" name="country" placeholder="Country" required data-validation-required-message="Please enter your Country of residence">
<div class="help-block"></div>
</div>
</div>
<!-- Zip/Postal Code -->
<div class="form-group">
<label class="control-label col-md-4" for="zip"><abbr title="Required field">*</abbr>Zip/Postal Code</label>
<div class="col-md-8">
<input type="text" class="form-control" id="zip" name="zip" placeholder="Zip/Postal Code" required data-validation-required-message="Please enter your Zip or Postal Code">
<div class="help-block"></div>
</div>
</div>
<!-- Phone -->
<div class="form-group">
<label class="control-label col-md-4" for="phone">Phone</label>
<div class="col-md-8">
<input type="tel" class="form-control" id="phone" name="phone" placeholder="Phone">
</div>
</div>
<!-- Email Address -->
<div class="form-group">
<label class="control-label col-md-4" for="email"><abbr title="Required field">*</abbr>Email address</label>
<div class="col-md-8">
<input type="email" class="form-control" id="email" name="email" placeholder="Email Address" required data-validation-required-message="Please enter your email">
<div class="help-block"></div>
</div>
</div>
<!-- Mailing List -->
<div class="form-group">
<label class="control-label col-md-4" for="checkbox">Include in mailing list</label>
<div class="col-md-8">
<input type="checkbox" class="form-control" id="checkbox" name="checkbox" value="1">
</div>
</div>
<!-- Comment -->
<div class="form-group">
<label class="control-label col-md-4" for="comment">Comment</label>
<div class="col-md-8">
<textarea class="form-control" id="comment" name="comment" rows="3"></textarea>
</div>
</div>
<!-- Buttons -->
<div class="form-group">
<div class="col-md-8 col-md-offset-4">
<div id="success"> </div> <!-- For success/fail messages -->
<button type="submit" class="btn btn-primary pull-right">Submit</button>
</div>
</div>
</form>
UPDATE 8:50PM 03/09
I uploaded this to a different host and now, when I submit the form I'm getting an error :"Message cannot be sent!"
you are sending the email to "email#example.com"
Probably try sending it to your email address, by changing the $to variable.
Also change the headers. From This
$headers = "From: $email_address\n";
$headers = "Reply-To: $email_address";
To:
$headers = "From: $email_address\n";
$headers .= "Reply-To: $email_address";
note the .= on the second line, this means add the string onto headers vs replacing the content of the variable.
And maybe change this:
mail($to,$email_subject,$email_body,$headers);
return true;
to
return mail($to,$email_subject,$email_body,$headers); // will return true on success send, or false if it failed to send.