Contact us form: Mail not received [duplicate] - 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

Related

Why isn't my PHP form working? I do receive the email but there is no content in it

PHP form on my website isn't responding well. It would be appreciated if someone could help me.
This is the HTML Code of the form
<form action="contactform.php" method="post" name="form" class="p-5 bg-white">
<div class="row form-group">
<div class="col-md-6 mb-3 mb-md-0">
<label class="text-black" for="fname">First Name</label>
<input type="text" id="fname" class="form-control">
</div>
<div class="col-md-6">
<label class="text-black" for="lname">Last Name</label>
<input type="text" id="lname" class="form-control">
</div>
</div>
<div class="row form-group">
<div class="col-md-12">
<label class="text-black" for="email">Email</label>
<input type="email" id="email" class="form-control">
</div>
</div>
<div class="row form-group">
<div class="col-md-12">
<label class="text-black" for="subject">Subject</label>
<input type="subject" id="subject" class="form-control">
</div>
</div>
<div class="row form-group">
<div class="col-md-12">
<label class="text-black" for="mssg">Message</label>
<textarea name="mssg" id="mssg" cols="30" rows="7" class="form-control" placeholder="Write your notes or questions here..."></textarea>
</div>
</div>
<div class="row form-group">
<div class="col-md-12">
<input type="submit" value="Send Message" class="btn btn-primary py-2 px-4 text-white">
</div>
</div>
</form>
This is the PHP Code
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$to = "alyyashar#gmail.com";
$subject = "New email from your site!";
$fname = $_POST['fname'];
$email = $_POST['email'];
$message = $_POST['message'];
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
$title = '<h3>Hello! You have received a new mail from your website!</h3>';
$body = "$title
<br/>
<b>From:</b> $fname
<br/>
<b>E-Mail:</b> $email
<br/>
<b>Message:</b>\n$message
<br/>
<br/>";
if (mail($to, $subject, $body, $headers)){
echo "<h1>Sent Successfully! Thank you"." ".$fname.", We will contact you shortly!</h1>";
} else {
echo "Something went wrong!";
}
}
?>
<br>
Back to Homepage
This is the email I receive
Screenshot of the email
When I enter information into the form and click send message, I do receive the email but there is no content in it.
The form elements have no name attributes, which is what the browser uses to send their name/value pairs to the server. So while it's posting the form, none of the values are being included.
For example, this:
<input type="text" id="fname" class="form-control">
Should be this:
<input type="text" id="fname" class="form-control" name="fname">
The same fix would need to be repeated for the remaining form elements.

PHP sending email but not getting data from HTML Form [duplicate]

This question already has answers here:
empty $_POST in PHP mail()
(2 answers)
phpmailer how to check if field is empty sintax
(2 answers)
Closed 4 years ago.
I am trying to get some data, like name, email, etc. from an HTML form and sending that data to my gmail. I am getting an email with 'You have recieved an email from .' and 'No Sender' and 'No subject' as the email details.
Here is the PHP:
<?php
if(isset($_POST['submit'])) {
$name = $_POST['first_name'];
$subject = $_POST['subject'];
$mailFrom = $_POST['email'];
$message = $_POST['message'];
$mailTo = "tamiroffen#gmail.com";
$headers = "From: " . $mailFrom;
$txt = "You have recieved an email from " . $name . ".\n\n" . $message;
mail($mailTo, $subject, $txt, $headers);
header("Location: index.html?mailsend");
}
?>
Here is the form section snippet of the HTML:
<form action="contact_form_process.php" method="POST">
<section id="contact" class="py-3">
<div class="container">
<div class="row">
<div class="col-md-9 mx-auto">
<div class="card p-4">
<div class="card-body">
<h3 class="text-center lato-font">Please Fill Out This Form To Contact Us</h3>
<hr>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<input id="first_name" name="first_name" type="text" class="form-control" placeholder="First Name">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<input id="last_name" type="text" class="form-control" placeholder="Last Name">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<input id="email" type="text" class="form-control" placeholder="Email">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<input id="phone_num" type="text" class="form-control" placeholder="Phone Number">
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<textarea class="form-control" name="" id="message" rows="10" placeholder="Message"></textarea>
</div>
</div>
</div>
</div>
<div class="card-footer">
<button type="submit" name="submit" class="btn btn-outline-success btn-block">Send</button>
</div>
</div>
</div>
</div>
</div>
</section>
</form>

Unable to send an email after clicking on submit button in php

Trying to send an email not displaying any error message or anything just refreshing the page that it.
I am trying an email through contact form but its not working.Here is the code for that. tried by doing echo but it is not working .not displaying any error as well.
contact and contactus:
<?php ob_start();
if(isset($_POST['submit'])) {
$to = "abc#gmail.com";
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$txt = $_POST['comment'];
$headers = "From: " .$email . "\r\n" .
"CC: xyz#gmail.com";
mail($to,$subject,$txt,$headers);
header("Location: contact.php");
}
?>
<!DOCTYPE html>
<html>
<head>
<title>HMS System</title>
</head>
<body>
<div class="container">
<div class="page-header">
<h2>Contact Us Form</h2>
</div>
<form class="form-horizontal" action="contactus.php" method="post" role="form">
<div class="form-group">
<label for="name" class="col-sm-2 control-label">Name</label>
<div class="col-sm-8">
<input type="text" class="form-control" name="name" placeholder="Insert your Name" id="name">
</div>
</div>
<div class="form-group">
<label for="email" class="col-sm-2 control-label">Email Address</label>
<div class="col-sm-8">
<input type="email" class="form-control" name="email" placeholder="Email Address" id="email">
</div>
</div>
<div class="form-group">
<label for="subject" class="col-sm-2 control-label">Subject</label>
<div class="col-sm-8">
<input type="text" class="form-control" name="subject" placeholder="Subject" id="subject">
</div>
</div>
<div class="form-group">
<label for="comments" class="col-sm-2 control-label">Comment</label>
<div class="col-sm-8">
<textarea class="form-control" rows="10" name="comment" style="resize:none;"></textarea>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label"></label>
<div class="col-sm-8">
<input type="submit" value="Send Message" name="submit_contact" class="btn btn-block btn-danger" id="subject">
</div>
</div>
</form>
</section>
</article>
</div>
<div style="width:50px;height:50px;"></div>
</body>
use this
if(isset($_POST['submit_contact']))
If you are doing it from your local server, you will have to setup your mail properly in ini then only you will be able to send mail from your local machine.
A better approach would be to wrap the mail function in a statement. Mail is returning a bool value. And beginn as simple as possible.
error_reporting (E_ALL);
$to = "mail#whatever.com"
// ... your settings ...
if ( mail ( $to , $subject , $message ) ) {
// do when ok
}
else {
// do when error
}
To verify that you receive all values from $_POST do
echo '<pre>';
print_r ($_POST);
echo '</pre>';

php form email not sending when action = submit to self [duplicate]

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...

PHP Email Form Won't Send Email - Can't Figure This Out [duplicate]

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 ^

Categories