I am able to receive email with all the information except for the email address that is entered in the form, and when I receive the email, I get "No Sender" instead of the person's name or email.
This is my HTML:
<!-- Contact Form -->
<div class="col-xs-12 col-sm-8 col-md-8">
<div id="contant-form-bx" class="contant-form-bx">
<div class="contact-loader"></div>
<form action="mail.php" id="contact-form" class="contact-form" name="cform" method="post">
<div class="row">
<div class="col-md-6">
<label for="name" id="name_label">Name</label>
<span class="name-missing">Please enter your name!</span>
<input id="name" type="text" value="" name="name" size="30">
</div>
<div class="col-md-6 columns">
<label for="e-mail" id="email_label">Email</label>
<span class="email-missing">Please enter a valid e-mail!</span>
<input id="e-mail" type="text" value="" name="email" size="30">
</div>
<div class="col-md-12">
<label for="message" id="phone_label">Message</label>
<span class="message-missing">Say something!</span>
<textarea id="message" name="message" rows="7" cols="40"></textarea>
</div>
<div class="col-md-12 text-center">
<input type="submit" name="submit" class="button" id="submit_btn" value="Send Message">
</div>
</div>
</form>
</div>
</div>
This is my PHP:
<?php
// declare our variables
$name = $_POST['name'];
$email = $_POST['e-mail'];
$message = nl2br($_POST['message']);
// set a title for the message
$subject = "From $name via WEB";
$body = "From $name, \n\n$message";
$headers = 'From: '.$email.'' . "\r\n" .
'Reply-To: '.$email.'' . "\r\n" .
'Content-type: text/html; charset=utf-8' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
// put your email address here
mail("info#wziel.com", $subject, $body, $headers);
?>
<!--Display a Thank you message in the callback -->
<div class="mail_response">
<h4>Thank you <?php echo $name ?>!</h4>
<p>I'll be in touch real soon!</p>
</div>
According to your form this:
$email = $_POST['e-mail'];
Should be this:
$email = $_POST['email'];
You have e-mail as the id not the name.
The php looks at name and not id
You're using $_POST['e-mail']. e-mail is the ID of the <input> tag. You should be using $_POST['email'] because name="email".
Related
I have a form where a receptionist enters a visitors information, first name, email etc and I want to send an email to the visitor using their email address entered in the form.
I have the php mail function working however it currently only sends to a specific sender that I manually specify. How do I make the submit button on this form send an email based on the contents of the email field?
I assume I need to do something like this
<?php
$to = $row['email'];
$subject = 'Welcome ' . $row['first_name'] . ';
$message = 'You have been booked in';
$headers = 'From: noreply#blah.com' . "\r\n" .
'Reply-To: noreply#blah.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
I dont think the $row[] is correct as I want to pull from the form, not the table that the form is inputting into.
This is the form page:
//serve POST method, After successful insert, redirect to customers.php page.
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
//Mass Insert Data. Keep "name" attribute in html form same as column name in mysql table.
$data_to_store = filter_input_array(INPUT_POST);
//Insert timestamp
$db = getDbInstance();
$last_id = $db->insert ('tb_bookings', $data_to_store);
if($last_id)
{
$_SESSION['success'] = "Visitor signed in successfully!";
header('location: bookings.php');
exit();
}
}
//We are using same form for adding and editing. This is a create form so declare $edit = false.
$edit = false;
require_once('includes/admin-header.php');
?>
<div id="page-wrapper">
<div class="row">
<div class="col-lg-12">
<h2 class="page-header">Manual Sign-in</h2>
</div>
</div>
<form class="form" action="" method="post" id="visitor_form" enctype="multipart/form-data">
<?php include_once('../forms/prebook_form.php'); ?>
</form>
</div>
And this is the form:
<fieldset>
<div class="form-group">
<label for="f_name">First Name *</label>
<input type="text" name="first_name" value="<?php echo $edit ? $tb_bookings['first_name'] : ''; ?>" placeholder="First Name" class="form-control" required="required" id = "first_name" >
</div>
<div class="form-group">
<label for="l_name">Last name *</label>
<input type="text" name="last_name" value="<?php echo $edit ? $tb_bookings['last_name'] : ''; ?>" placeholder="Last Name" class="form-control" required="required" id="last_name">
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="email" name="email" value="<?php echo $edit ? $tb_bookings['email'] : ''; ?>" placeholder="E-Mail Address" class="form-control" id="email">
</div>
<div class="form-group">
<label>Visiting Date</label>
<input name="visiting_date" value="<?php echo $edit ? $tb_bookings['visiting_date'] : ''; ?>" placeholder="Visiting Date" class="form-control" type="date">
</div>
<div class="form-group">
<label>Visiting</label>
<input name="visiting" value="<?php echo $edit ? $tb_bookings['visiting_date'] : ''; ?>" placeholder="Who are they visiting?" class="form-control" id="visiting">
</div>
<div class="form-group text-center">
<label></label>
<button type="submit" class="btn btn-warning" >Save <span class="glyphicon glyphicon-send"></span></button>
</div>
</fieldset>
maybe something like this...
if (isset($_POST['submit'])) {
$to = $_POST['email'];
$name = $_POST['first_name'];
$subject = 'Welcome ' . $name;
$message = 'You have been booked in';
$headers = 'From: noreply#blah.com' . "\r\n" .
'Reply-To: noreply#blah.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
}
When I try to click sent button, the content from the webpage is not redirecting to the .php page.I am using recaptcha in the form .Can you please help me to solve this issue..
my HTML code is:
<form action="sendform.php" id="contact-form" class="form-horizontal"
method="post">
<fieldset>
<div class="form-group">
<label class="col-sm-4 control-label" for="name">Your Name</label>
<div class="col-sm-8">
<input type="text" placeholder="Your Name" class="form-control" name="name" id="name">
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label" for="email">Email Address</label>
<div class="col-sm-8">
<input type="text" placeholder="Enter Your Email Address" class="form-control" name="email" id="email">
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label" for="subject">Subject</label>
<div class="col-sm-8">
<input type="text" placeholder="Subject" class="form-control" name="subject" id="subject" list="exampleList">
<datalist id="exampleList" >
<option value="a">A</option>
<option value="b">B Combo</option>
</datalist>
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label" for="message">Your Message</label>
<div class="col-sm-8">
<textarea placeholder="Please Type Your Message" class="form-control" name="message" id="message" rows="3"></textarea>
</div>
</div>
<div class="col-sm-8" class="form-group" class="g-recaptcha" data-sitekey="xxxxxxyyyyyyy"></div>
<div class="col-sm-offset-4 col-sm-8">
<button type="submit" value="Send" id="submit" name="submit" class="submit_btn float_l">Submit</button>
<button type="reset" class="btn btn-primary">Cancel</button>
</div>
</fieldset>
</form>
And my PHP Code sendform.php
<?php
if (isset($_POST['submit']) && !empty($_POST['submit'])):
if (isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])):
//your site secret key
$secret = 'xxxxxxxxxxxxx';
//get verify response data
$verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret=' . $secret . '&response=' . $_POST['g-recaptcha-response']);
$responseData = json_decode($verifyResponse);
if ($responseData->success):
$to = "aaa#abc.com"; // this is your Email address
$from = !empty($_POST['email']) ? $_POST['email'] : ''; // this is the sender's Email address
$name = !empty($_POST['name']) ? $_POST['name'] : '';
$subject = !empty($_POST['subject']) ? $_POST['subject'] : '';
$subject2 = "Copy of your form submission";
$message = $first_name . " " . $last_name . " wrote the following:" . "\n\n" . $_POST['message'];
$message2 = "Here is a copy of your message " . $first_name . "\n\n" . $_POST['message'];
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers = "From:" . $from;
$headers .= 'From:' . $name . ' <' . $from . '>' . "\r\n";
$headers2 = "From:" . $to;
mail($to, $subject, $message, $headers);
$succMsg = 'Your request have submitted successfully.';
else:
$errMsg = 'Robot verification failed, please try again.';
endif;
else:
$errMsg = 'Please click on the reCAPTCHA box.';
endif;
else:
$errMsg = '';
$succMsg = '';
endif;
?>
I have tested your code and it works.
Please make sure that you have placed your html and php files in same directory and also your files should be served via a local running server.
So your url should look like this http://localhost/testing/index.html
Although, your sendform.php gives me captcha error ofcourse.
"Please click on the reCAPTCHA box."
I have a simple contact form, the html is this part:
<!-- CONTACT FORM -->
<form id="contact-form" name="contactform" class="row">
<!-- CONTACT FORM IMPUT -->
<div id="input_name" class="col-md-12">
<input type="text" name="name" id="name" class="form-control" placeholder="Il tuo nome">
</div>
<div id="input_email" class="col-md-12">
<input type="text" name="email" id="email" class="form-control" placeholder="Email">
</div>
<div id="input_subject" class="col-md-12">
<input type="text" name="subject" id="subject" class="form-control" placeholder="Numero di telefono">
</div>
<div id="input_message" class="col-md-12">
<textarea class="form-control" name="message" id="message" rows="6" placeholder="Il tuo messaggio..."></textarea>
</div>
<div class="col-md-12 sinistra"><br>Quale servizio ti interessa?<br><br></div>
<div class="col-md-4 sinistra">
<input type="radio" name="tipologia" value="standard"> Standard<br>
</div>
<div class="col-md-4 sinistra">
<input type="radio" name="tipologia" value="avanzato"> Avanzato<br>
</div>
<div class="col-md-4 sinistra">
<input type="radio" name="tipologia" value="deluxe"> Deluxe<br>
</div>
<div class="col-md-12"><br></div>
<!-- CONTACT FORM SUBMIT BUTTON -->
<div id="form_btn" class="col-md-12">
<input type="submit" value="Invia" id="submit" class="btn btn-small btn-blue">
</div>
<!-- CONTACT FORM MESSAGE -->
<div class="col-md-12 contact-form-msg">
<span class="loading"></span>
</div>
</form>
with this php file
<?
$name = $_REQUEST["name"];
$email = $_REQUEST["email"];
$subject = $_REQUEST["subject"];
$msg = $_POST["msg"];
$tipologia = $_POST['tipologia'] ;
$to = "info#gmail.com";
if (isset($email) && isset($name) && isset($msg) ) {
$email_subject = "$name ha inviato una richiesta di ordine";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= "Da: ".$name." <".$email.">\r\n"."Reply-To: ".$email."\r\n" ;
$msg = "Da: $name<br/> Email: $email <br/> Telefono: $subject <br/>
Tipologia: $tipologia <br/> Messaggio: $msg";
$mail = mail($to, $email_subject, $msg, $headers);
if($mail)
{
echo 'success';
}
else
{
echo 'failed';
}
}
?>
but I have a problem with radio input, the form works but doesn't pass the value of radio to email, so the email has the Tipologia without the radio selected for the form... What could be the error?
<form> defaults to a GET method if POST isn't implied.
You're using two POST arrays.
So... use a POST method and all POST arrays.
Either way, everything must match.
You should also check if the radio buttons are set or not, or any other you wish to include.
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 6 years ago.
am trying to use PHP to send mails from a form using one page submission but i seem to be missing something since no mail is sent on submission neither does it throw up an error (which is rather weird). Below is the PHP and HTML form codes which are on the same file
PHP Script
<?php
if (isset($_POST["submit"])) {
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$from = 'From: risingventures.com.ng';
$to = 'inquiry#risingventures.com.ng';
$subject = 'New message from contact form';
$body = "From: $name\n E-mail: $email\n Phone: $phone\n Message:\n $message";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html\r\n";
$headers = 'From: from#example.com' . "\r\n" .
'Reply-To: reply#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
if (mail($to, $subject, $body, $headers)) {
$result = '<div class="alert alert-success">Thank You! We will be in touch with you soon</div>';
} else {
$result = '<div class="alert alert-danger">Sorry! There was an error submitting your message. Please try again</div>';
}
}
?>
HTML code
<form action="contact.php" method="POST" role="form">
<legend>Contact Us</legend>
<div class="form-group">
<div class="col-lg-12" style="margin-bottom: 20px">
<label>Name *</label>
<input type="text" class="form-control" name="name" placeholder="Please type your Firstname followed by your Lastname">
</div>
</div>
<div class="form-group" style="margin-bottom: 20px">
<div class="col-lg-6">
<label>Email *</label>
<input type="email" class="form-control" name="email" placeholder="Please type in your email address *">
</div>
</div>
<div class="form-group" style="margin-bottom: 20px">
<div class="col-lg-6" style="margin-bottom: 20px">
<label>Phone</label>
<input type="tel" class="form-control" name="phone" placeholder="Please type in your phone number">
</div>
</div>
<div class="form-group" style="margin-bottom: 20px">
<div class="col-lg-12" style="margin-bottom: 20px">
<label>Message *</label>
<textarea class="form-control" name="message" rows="6"></textarea>
</div>
</div>
<div class="form-group" style="margin-bottom: 20px">
<div class="col-lg-12" style="margin-bottom: 20px">
<input type="submit" class="btn btn-primary" value="Send Message">
</div>
</div>
<div class="form-group" style="margin-bottom: 20px">
<div class="col-lg-12" style="margin-bottom: 10px">
<p class="text-muted"><strong>*</strong> These fields are required.</p>
</div>
</div>
</form>
after I have checked the form tag of your html, I observed the following
The enctype attribute that specifies how the form-data should be encoded when submitting it to the server was absent, the enctype attribute is required if method="post". this can be either multipart/form-data,text/plain, or application/x-www-form-urlencoded
if this does not fix it remove the role = form and try again
I am using a simple html form as a contact, and when fields and submitted the form does not clear the fields.
this is my php
I read online in few places and I've learned that I have to use the .reset , but I am not familiar with php a lot. I am not sure where would I add the .reset and how.
<?
$name = $_REQUEST["name"];
$email = $_REQUEST["email"];
$msg = $_REQUEST["msg"];
$to = "example#example.com";
if (isset($email) && isset($name) && isset($msg)) {
$subject = "Message / Closure Film";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= "From: ".$name." <".$email.">\r\n"."Reply-To: ".$email."\r\n" ;
$msg = "Name: $name:<br/> Email: $email <br/> Message: $msg";
$mail = mail($to, $subject, $msg, $headers);
if($mail)
{
echo 'success';
}
else
{
echo 'failed';
}
}
?>
my html
<div id="contact">
<div class="container">
<div class="row-fluid PageHead">
<div class="span12">
<h3>CONTACT US<span> <img src="images/underline.png" alt="______"></span></h3>
</div>
</div>
<div class="row-fluid ContactUs">
<div class="span6 offset3">
<form class="form-horizontal" id="phpcontactform">
<div class="control-group">
<input class="input-block-level" type="text" placeholder="Full Name" name="name" id="name">
</div>
<div class="control-group">
<input class="input-block-level" type="email" placeholder="Email" name="email" id="email">
</div>
<div class="control-group">
<textarea class="input-block-level" rows="10" name="message" placeholder="Your Message" id="message"></textarea>
</div>
<div class="control-group">
<p>
<input class="btn btn-danger btn-large" type="submit" value="Send Message">
</p>
<span class="loading"></span> </div>
</form>
</div>
added this to the head of my html, but didnt get any result
<script type="javascript">
$('#phpcontactform').trigger("reset");
</script>
Try:
<script type="javascript">
$(document).ready(function() {
$('#phpcontactform')[0].reset();
});
</script>
I'm not sure if you're trying to do an ajax submit and keep the user on the page, or just submit the form. But the line you're looking for is $("#phpcontactform")[0].reset();, you could wrap that in a $(document).ready() if you needed to!