send mail feature in html + php - php

I want to send an email with PHP when a user has finished filling in an HTML form and then emailing information from the form. I have below code but was not getting form values in mail. Can someone help me regarding this?
<form id="main-contact-form" class="contact-form" name="contact-form" method="post" action="sendemail.php" role="form">
<div class="row">
<div class="col-sm-5">
<div class="form-group">
<input type="text" class="form-control" required="required" placeholder="First Name" name="name">
</div>
<div class="form-group">
<input type="text" class="form-control" required="required" placeholder="Last Name" name="lname">
</div>
<div class="form-group">
<input type="text" class="form-control" required="required" placeholder="Email address" name="email">
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary btn-lg" name="submit">Send Message</button>
</div>
</div>
<div class="col-sm-7">
<textarea name="message" id="message" required="required" class="form-control" rows="8" placeholder="Message"></textarea>
</div>
</div>
</form>
**sendemail.php**
<?php
header('Content-type: application/json');
$status = array(
'type'=>'success',
'message'=>'Email sent!'
);
$name = #trim(stripslashes($_POST['name']));
$email = #trim(stripslashes($_POST['email']));
$subject = "Mail from your website";
$message = #trim(stripslashes($_POST['message']));
$email_from = $email;
$email_to = 'manish22it#gmail.com';
$body = 'Name: ' . $name . "\n\n" . 'Email: ' . $email . "\n\n" . 'Subject: ' . $subject . "\n\n" . 'Message: ' . $message;
$success = #mail($email_to, $subject, $body, 'From: <'.$email_from.'>');
echo json_encode($status);
die;
?>

Related

PHP: Contact us form does not echo success text

I have two html forms that both send emails successfully using PHP. However, one form echo successful submission text, but the other one does not.
Here is the form that is part of the index.html page, which does not echo any text after submission. Please note, the email still sends:
<form class="booking-form" id="myForm" action="#">
<div class="row">
<div class="col-lg-12 d-flex flex-column">
<input name="name" placeholder="Your name" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Your Name'" class="form-control mt-20" required="" type="text">
</div>
<div class="col-lg-6 d-flex flex-column">
<input name="subject" placeholder="subject" onfocus="this.placeholder = ''" onblur="this.placeholder = 'subject'" class="form-control mt-20" required="" type="text">
</div>
<div class="col-lg-6 d-flex flex-column">
<input name="email" placeholder="Email" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Email'" class="form-control mt-20" required="" type="email">
</div>
<div class="col-lg-12 flex-column">
<textarea rows="5" class="form-control mt-20" name="message" placeholder="Messege" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Messege'" required=""></textarea>
</div>
<div class="col-lg-12 d-flex justify-content-end send-btn">
<button type="submit" class="genric-btn primary mt-20 text-uppercase ">Send</button>
</div>
</div>
</form>
The following is the PHP mailer code:
<?php
$to = 'myEmail#gmail.com';
$firstname = $_POST["name"];
$email= $_POST["email"];
$text= $_POST["message"];
$subject= $_POST["subject"];
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= "From: Email coming from Brave Towing " . $email . "\r\n"; // Sender's E-mail
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$message = "
<html>
<head>
</head>
<body style=\"background-color:#fafafa;\">
<div style=\"padding:20px;\">
Customer Email: <span style=\"color:#888\">$email</span>
<br>
Contact Subject: <span style=\"color:#888\">$subject</span>
<br>
Contact Message: <div style=\"color:#888\">$text</div>
</div>
</body>
</html>
";
if (#mail($to, $email, $message, $headers))
{
echo '<h1>The message has been sent</h1>';
}else{
echo 'failed';
}
?>

not receiving php mail() messages from remote host

I have a email form Here and am invoking the mail() function. for some reason I am not receiving any emails to my email account. My only guess is that it could be some config on the server
Here is my php script:
<?php
header('Content-type: application/json');
$status = array(
'type'=>'success',
'message'=>'Email sent!'
);
$name = #trim(stripslashes($_POST['name']));
$email = #trim(stripslashes($_POST['email']));
$subject = #trim(stripslashes($_POST['subject']));
$message = #trim(stripslashes($_POST['message']));
$email_from = $email;
$email_to = 'keilcarpenter01#gmail.com';
$body = 'Name: ' . $name . "\n\n" . 'Email: ' . $email . "\n\n" . 'Subject: ' . $subject . "\n\n" . 'Message: ' . $message;
$success = #mail($email_to, $subject, $body, 'From: <'.$email_from.'>');
echo json_encode($status);
die;
And the html form:
<h1>Contact Form</h1>
<p>Send me a message and I will get back to you!</p>
<div class="status alert alert-success" style="display: none"></div>
<form id="main-contact-form" class="contact-form" name="contact-form" method="post" action="sendemail.php" role="form">
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<input type="text" name="name" class="form-control" required="required" placeholder="Name">
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<input type="text" name="email" class="form-control" required="required" placeholder="Email address">
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div class="form-group">
<textarea name="message" id="message" required="required" class="form-control" rows="8" placeholder="Message"></textarea>
</div>
<div class="form-group">
<button type="submit" class="btn btn-danger btn-lg">Send Message</button>
</div>
</div>
</div>
</form>
Could it be some config on the remote host or something wrong on my end?
I read that if your sending from localhost then you need to config the php.ini and sendmail.ini so I know that is out of the question.
Would PHPMailer be better to use?

Form Values Not fetching

This is a contact form, when I click on submit button I am receiving the mail but form values are not fetched. I am unable to find the problem. Can someone help me?
here i include my code:
<?php
header('Content-type: application/json');
$status = array(
'type'=>'success',
'message'=>'Email sent!'
);
$name = #trim(stripslashes($_POST['fn']));
$email = #trim(stripslashes($_POST['ln']));
$subject = #trim(stripslashes($_POST['email']));
$message = #trim(stripslashes($_POST['message']));
$sub = 'mail from xxxx.com';
$email_from = $subject;
$email_to = 'xxxx#gmail.com';
$body = 'Name: ' . $name . "\n\n" . 'Email: ' . $email . "\n\n" . 'Subject: ' . $subject . "\n\n" . 'Message: ' . $message;
$success = #mail($email_to, $sub, $body, 'From: <'.$email_from.'>');
echo json_encode($status);
die;
?>
<form id="main-contact-form" class="contact-form" name="contact-form" action="send.php" method="post"">
<div class="row-fluid">
<div class="span5">
<label>First Name</label>
<input type="text" name="fn" class="input-block-level" required="required" placeholder="Your First Name">
<label>Last Name</label>
<input type="text" name="ln" class="input-block-level" required="required" placeholder="Your Last Name">
<label>Email Address</label>
<input type="text" name="email" class="input-block-level" required="required" placeholder="Your email address">
</div>
<div class="span7">
<label>Message</label>
<textarea name="message" id="message" required="required" class="input-block-level" rows="8"></textarea>
</div>
</div>
<input type="submit" >
<p> </p>
</form>
I can solve this problem with silly mistake....
<form id="main-contact-form" class="contact-form" name="contact-form" action="send.php" method="post"">
in this line i can give so changes is
<form id="main-contact-form" class="contact-form" name="contact-form" action="send.php" method="post">

Php Error with Contact Form email received without content

I have a contact form using php however when I test the form I receive an email with no content in the fields, I have checked that the fields match with the php but cannot seem to identify the problem.
The form html part of the contact page:
<section id="contact-page">
<div class="container">
<div class="center">
<h2>Send us a Message</h2>
<p class="lead">Thanks for your enquiry we will respond within 24 hours. * Indicates required information</p>
</div>
<div class="row contact-wrap">
<div class="status alert alert-success" style="display: none"></div>
<form action="sendemail2.php" method="post" id="main-contact-form" class="contact-form" name="contact-form" >
<div class="col-sm-5 col-sm-offset-1">
<div class="form-group">
<label>Name *</label>
<input type="text" name="name" class="form-control" required>
</div>
<div class="form-group">
<label>Email *</label>
<input type="email" name="email" class="form-control" required>
</div>
<div class="form-group">
<label>Phone</label>
<input type="number" name="tel"class="form-control">
</div>
<div class="form-group">
<label>Company Name</label>
<input type="text" name="company" class="form-control">
</div>
</div>
<div class="col-sm-5">
<div class="form-group">
<label>Subject *</label>
<input type="text" name="subject" class="form-control" required>
</div>
<div class="form-group">
<label>Message *</label>
<textarea name="message" id="message" required class="form-control" rows="8"></textarea>
</div>
<div class="form-group">
<button type="submit" name="submit" class="btn btn-primary btn-lg" required="required">Submit Message</button>
</div>
</div>
</form>
</div><!--/.row-->
</div><!--/.container-->
</section><!--/#contact-page-->
The Php script:
<?php
header('Content-type: application/json');
$status = array(
//'type'=>'success',
//'message'=>
'Thank you for contacting us. As early as possible we will contact you '
);
$name = #trim(stripslashes($_POST["name"]));
$email = #trim(stripslashes($_POST["email"]));
$subject = #trim(stripslashes($_POST["subject"]));
$tel = #trim(stripslashes($_POST["tel"]));
$company = #trim(stripslashes($_POST["company"]));
$message = #trim(stripslashes($_POST["message"]));
$email_from = $email;
$email_to = 'xxx#xxx.com';//replace with your email
$body = 'Name: ' . $name . "\n\n" . 'Email: ' . $email . "\n\n" . 'Subject: ' . $subject . "\n\n" . 'Phone Number: ' . $tel . "\n\n" .'Company Name : ' . $company . "\n\n" . 'Message: ' . $message;
$success = #mail($email_to, $subject, $body, 'From: <'.$email_from.'>');
echo json_encode($status);
die;
Any help would be appreciated.
Thanks
or use
<form method="post" id="main-contact-form" class="contact-form" name="contact-form" >
in place of
<form action="sendemail2.php" method="post" id="main-contact-form" class="contact-form" name="contact-form" >

Contact form sends email but without user inputs

This bootstrap using html/php contact form sends me an email just fine, but without any of the users input information!
The email I received looks empty like this:
Name:
Email:
Subject:
Message:
The html for the form is:
<section id="partner">
<div class="container">
<div class="center wow fadeInDown">
<h2><br>Contact</h2>
<p class="lead">Send a general enquiry here or order your service here.</p>
</div>
<div class="row contact-wrap">
<div class="status alert alert-success" style="display: none"></div>
<form id="main-contact-form" class="contact-form" name="contact-form" method="post" action="sendemail.php">
<div class="col-sm-5 col-sm-offset-1">
<div class="form-group">
<label>Name *</label>
<input type="text" name="name" class="form-control" required="required">
</div>
<div class="form-group">
<label>Email *</label>
<input type="email" name="email" class="form-control" required="required">
</div>
<div class="form-group">
<label>Phone</label>
<input type="number" class="form-control">
</div>
<div class="form-group">
<label>Company Name</label>
<input type="text" class="form-control">
</div>
</div>
<div class="col-sm-5">
<div class="form-group">
<label>Subject *</label>
<input type="text" name="subject" class="form-control" required="required">
</div>
<div class="form-group">
<label>Message *</label>
<textarea name="message" id="message" required="required" class="form-control" rows="8"></textarea>
</div>
<div class="form-group">
<button type="submit" name="submit" class="btn btn-primary btn-lg" required="required">Submit Message</button>
</div>
</div>
</form>
</div><!--/.row-->
</div><!--/.container-->
</section><!--/#contact-page-->
The PHP for the form looks like this:
<?php
header('Content-type: application/json');
$status = array(
'type'=>'success',
'message'=>'Thank you for contact us. As early as possible we will contact you '
);
$name = #trim(stripslashes($_POST['name']));
$email = #trim(stripslashes($_POST['email']));
$subject = #trim(stripslashes($_POST['subject']));
$message = #trim(stripslashes($_POST['message']));
$email_from = $email;
$email_to = 'heerschapnikki#gmail.com';//replace with your email
$body = 'Name: ' . $name . "\n\n" . 'Email: ' . $email . "\n\n" . 'Subject: ' . $subject . "\n\n" . 'Message: ' . $message;
$success = #mail($email_to, $subject, $body, 'From: <'.$email_from.'>');
echo json_encode($status);
die;
Why isn't it working properly? The message "thank you for contacting us" pops up fine and the email sends through, but non of the users information comes through.
Try to print the values you are sending. So use this:
var_dump( $_POST['name'] );
var_dump( $_POST['email'] );
etc...
Doing this, you will be able to see wether your fields are even posted correctly.
the fields have no id param. in the post you get the "id" nor the "name"
<label>Name *</label>
<input type="text" id="name" class="form-control" required="required">
</div>
<div class="form-group">
<label>Email *</label>
<input type="email" id="email" class="form-control" required="required">

Categories