I currently have a contact form on my index.html & contact.html pages. When testing the PHP contact form they do not send me an email or give any notification that the message has been sent, just appearing to do nothing.
HTML
<div class="form">
<form action="php/contact.php" method="post">
<h5 class="grey-bg text-center iq-font-black iq-tw-6 iq-pall-20">Service Inquiry</h5>
<div class="iq-pall-30">
<div class="row">
<div class="col-sm-12 iq-mtb-10">
<div class="section-field">
<input name="name" placeholder="Name" id="name" type="text">
</div>
</div>
<div class="col-sm-12 iq-mtb-10">
<div class="section-field">
<input name="email" placeholder="Email" id="email" type="text">
</div>
</div>
<div class="col-sm-12 iq-mtb-10">
<div class="section-field">
<select name="service" id="service">
<option value="Choose Service" >Choose Service</option>
<option value="test1" >test1</option>
<option value="test" >Test</option>
<span class="error">A service is required</span>
</select>
</div>
</div>
<div class="col-sm-12 iq-mtb-10">
<div class="section-field">
<input name="phonenumber" placeholder="Phone Number" id="phonenumber" type="text">
</div>
</div>
<div class="col-sm-12 iq-mtb-10">
<div class="section-field ">
<textarea class="form-control" placeholder="Comment" rows="5" id="comment" style="resize: none;"></textarea>
</div>
</div>
<div class="col-sm-12 iq-mtb-10">
<button id="submit" name="submit" type="submit" value="Send" class="button pull-right iq-mt-20">Send Message</button>
</div>
</div>
</div>
</form>
</div>
PHP Code
<?php $ToEmail = 'test#test.com';
$EmailSubject = 'User Contact Information';
$mailheader = "From: ".$_POST["email"]."\r\n";
$mailheader .= "Reply-To: ".$_POST["email"]."\r\n";
$mailheader .= "Service: ".$_POST["service"]."\r\n";
$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";
$MESSAGE_BODY = "Name: ".$_POST["name"]."";
$MESSAGE_BODY .= "Email: ".$_POST["email"]."";
$MESSAGE_BODY .= "Service: ".$_POST["service"]."";
$MESSAGE_BODY .= "Phone: ".$_POST["phone"]."";
$MESSAGE_BODY .= "Comment: ".nl2br($_POST["message"])."";
mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure");?>
The email's I do receive are like this:
User Contact Information
Name: Email: Phone: Comment:
Do the fields match the PHP form, and the send message button, how can that have a response for if the email has been sent or not?
A couple errors:
Your <div class="iq-pall-30"> and <div class="row"> elements are unclosed, which make your markup invalid and might affect the output you're getting to your PHP script.
You reference form elements that doesn't actually exist in your form:
$_POST["phone"] is probably supposed to be a reference to your HTML form element <input type="text" name="phonenumber">. You'll have to change your variable reference to $_POST["phonenumber"] to correctly retrieve the data.
$_POST["message"] is probably supposed to be a reference to your textarea form element, but you haven't assigned a name to that element in your markup. You should add name="message" as an attribute of the textarea in order to correctly retrieve that data.
Related
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 2 years ago.
I had my contact form up and running and I was doing a bit of housekeeping with how it actually looked when it arrived in my inbox. I dunno what I changed but even after reverting it back to when I know it was working it no longer sends emails but it 100% was working at some point!
Maybe its an issue with the host or the server but I've no clue.
Here is the contact form php.
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$emailFrom = 'myemail#gmail.com';
$emailSubject = 'New Form Submission';
$emailBody = "Name: $name. \n".
"Email: $email. \n".
"Phone: $phone 'n".
"Message: $message.";
$to = 'myemail#gmail.com';
$headers = "From: $emailFrom \r\n";
$headers .= "Reply to $email \r\n";
mail($to,$emailSubject,$emailBody,$headers);
header("Location: index.php")
?>
And here is the forms html
<div id="contact" class="container contact-form">
<div id="contactAnchor"></div><!--CONTACT ANCHOR TAG-->
<div class="contact-image">
<img id="contactLogo" src="/img/sam avatar no bg.png" width="150px" alt="SDB logo"/>
</div>
<form method="post" action="contactform.php">
<h3>Drop Me a Message</h3>
<div class="row">
<div class="col">
<div class="form-group">
<input type="text" name="name" class="form-control" placeholder="Your Name *"/>
</div>
<div class="form-group">
<input type="text" name="email" class="form-control" placeholder="Your Email *"/>
</div>
<div class="form-group">
<input type="text" name="phone" class="form-control" placeholder="Your Phone Number"/>
</div>
</div>
<div class="col">
<div class="form-group">
<textarea name="message" class="form-control" placeholder="Your Message *" style="width: 100%; height: 150px;"></textarea>
</div>
<div class="form-group">
<input type="submit" name="btnSubmit" class="btn btn-success" value="Send Message" />
</div>
</div>
</div>
</form>
</div>
Not sure if this solves it, but your reply to header is incorrect:
$headers .= "Reply-To: $email \r\n";
I have a static site up (my portfolio site), with a form to send an email to me using a custom php.
the page is through github pages and the custom domain is through google.
the form is:
<div class="col-sm-12 col-md-6 wow fadeInUp" data-wow-duration="0.8s" data-wow-delay="0.2s">
<form id="contactForm" class="single-form quate-form wow fadeInUp" data-toggle="validator">
<div id="msgSubmit" class="h3 text-center hidden"></div>
<div class="row">
<div class="col-sm-12">
<input name="name" class="contact-name form-control" id="name" type="text" placeholder="First Name" required>
</div>
<div class="col-sm-12">
<input name="name" class="contact-email form-control" id="L_name" type="text" placeholder="Last Name" required>
</div>
<div class="col-sm-12">
<input name="name" class="contact-subject form-control" id="email" type="email" placeholder="Your Email" required>
</div>
<div class="col-sm-12">
<textarea class="contact-message" id="message" rows="6" placeholder="Your Message" required></textarea>
</div>
<!-- Subject Button -->
<div class="btn-form col-sm-12">
<button type="submit" class="btn btn-fill btn-block" id="form-submit">Send Message</button>
</div>
</div>
</form>
</div>
And the php to send it is:
<?php
$name = $_POST["name"];
$email = $_POST["email"];
$message = $_POST["message"];
$EmailTo = "#gmail.com";
$Subject = "Portfolio CV/Resume";
// prepare email body text
$Body .= "Name: ";
$Body .= $name;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $message;
$Body .= "\n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From:".$email);
// redirect to success page
if ($success){
echo "success";
}else{
echo "invalid";
}
?>
The actual error I get is:
POST https://codewithmarcus.com/process.php 405 jquery.min.js:4
I removed my actual email address from the code but rest assured it is in there correctly, any help would be appreciated.
405 http code means Not Allowed response status code indicates that the request method is known by the server but is not supported by the target resource.
And you won't be able to send email via Gmail through this script. To send email through Gmail, you need send it through SMPT server. You can use PHPmailer libraryfor that.
I have a form and the form is working: I receive all the details on my e-mail. But when I click submit, it redirects to a blank page with the text: "Request submitted successfully. We will contact with you very soon.".
What I would like to do is to show a green box saying that the form was submitted successfully, on the same page like most websites do, and not a redirect...
I am using Bootstrap :)
Mailer.php code:
<?php
$tipoIn = $_POST['tipoIn'];
$Tipologia_input = $_POST['Tipologia_input'];
$sender_name = $_POST['Nome'];
$sender_email = $_POST['email'];
$phone = $_POST['Telefone'];
$slider_value = $_POST['slider_value'];
$mail_body = $_POST['message'];
$body = $sender_name." sent a new message for you<br><br> Name: ".$sender_name."<br>Email: ".$sender_email."<br>Phone: ".$phone."<br>Tipo: ".$tipoIn."<br>Tipologia: ".$Tipologia_input."<br>Slider Value: ".$slider_value."<br>Message: ".$mail_body;
sendMail($sender_name , $sender_email, $body);
function sendMail($sender, $sender_mail, $body) {
$to = 'geral#porta10.com'; // Set Receiver Email Here
$myemail = 'geral#porta10.comm'; // Set Sender Email Here
$subject = "New EasyLoan Client"; // Set Subject Here
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: Lead <geral#porta10.com>\r\n"; // Set Header Here
$message = $body;
$sentmail = mail($to,$subject,$message,$headers);
if($sentmail) { echo "Request submitted successfully. We will contact with you very soon."; }
else { echo "Mail not sent"; }
}
?>
Form code:
<div class="form-container">
<div class="form-mockup">
<h2>Que imóvel procura ?</h2>
<!-- <h4>Easy to apply for a loan with us,Once you have complete this form. </h4>-->
<form action="mailer.php" method="post">
<div class="form-group">
<select class="form-control" id="tipo" name="tipoIn">
<option value="Tipo" disabled selected>Tipo de imóvel</option>
<option value="Moradia">Moradia</option>
<option value="Apartamento">Apartamento</option>
</select>
</div>
<div class="form-group">
<select class="form-control" id="tipologia" name="Tipologia_input">
<option value="Tipologia" disabled selected>Tipologia</option>
<option value="T1">T1</option>
<option value="T2">T2</option>
<option value="T3">T3</option>
<option value="T4">T4</option>
<option value="T5">T5</option>
</select>
</div>
<div class="form-group">
<input type="text" class="form-control" placeholder="Nome Completo" name="Nome">
</div>
<div class="form-group">
<input type="email" class="form-control" placeholder="E-mail" name="email">
</div>
<div class="form-group">
<input type="text" class="form-control" placeholder="Telefone" name="Telefone">
</div>
<div class="form-group">
<textarea class="form-control" rows="3" id="comentario" placeholder="Diga-nos como imagina a sua casa..." name="message"></textarea>
</div>
<div class="form-group">
<div class="button-slider">
<div class="btn-group btn_group">
<div class="btn btn-default btn_amount">Valor </div>
<div class="btn btn-default btn_slider">
<input id="bootstrap-slider" type="text" data-slider-min="1" data-slider-max="50000" data-slider-step="1" data-slider-value="25000" name="slider_value" />
<div class="valueLabel"><span class="text_span">Valor </span> <span id="sliderValue">25000</span>€</div>
</div>
</div>
</div>
</div>
<button type="submit" class="btn btn-default quote_btn">Enviar</button>
</form>
</div>
</div>
You can do various things, it depends on the framework or cms or the logic of your code. there are many ways to accomplish this task (showing on (same/existing) page and not redirecting to (blank/defaced)) but its still depends.
2 main ways i currently can imagine are:
Using Ajax and json for messaging between Server and client and
prevent reloading
Using session-keys to show up messages on any page user loads
afterwards.
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.
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!