PHP Contact form just.. stopped.. working [duplicate] - php

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";

Related

Contact Form submission failing?

I'm currently working on my portfolio. As of right now I'm trying to get the contact form to work. So I don't really know php that well and I'm not that good at it, but I've been googling and trying different ideas for myself. As of right now none of them have worked. Below I will attach the contact form html portion as well as the php I have now. Any help would be appreciated greatly
<section id="contact-form">
<!--Contact form section-->
<form method="POST" name="emailForm" action="index.php">
<!--Beginning of form and mail to my email address-->
<div class="contact-left">
<!--Contact info on the left side-->
<h1 class="c-l-heading">Contact</h1>
<!--Major heading-->
<div class="f-name">
<!--Name portion-->
<font>Name</font>
<input type="text" name="name" placeholder="Full Name" required/>
<!--Input field with a placeholder-->
</div>
<div class="f-email">
<!--email portion-->
<font >Email</font>
<input type="email" name="name" placeholder="Example#gmail.com" required/>
<!--Input field with a placeholder-->
</div>
</div>
<div class="contact-right">
<!--Contact info on the right side-->
<div class="message">
<!--Message portion-->
<font >Message</font>
<textarea name="message" rows="5" cols="20" placeholder="Write Message..." required></textarea>
<!--Textbox created-->
</div>
<button>submit</button>
<!--Submit button-->
</div>
</form>
</section>
PHP section now:
<?php
if(!isset($_POST['submit']))
{
echo "Error! You need to submit the form!";
}
//Collection
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$message = $_POST['message'];
//Validation
if(empty($name) || empty($visitor_email))
{
echo "Name and email are required"
exit;
}
$email_from = 'desmondlambkin17#gmail.com';
$email_subject = "dnjls.ca Contact Submission";
$email_body = "Name: $name\n"
"Email address: $visitor_email\n"
"Message: $message";
$to = "desmondlambkin17#gmail.com";
$headers = "From: $email_from";
//Send Email
mail($to, $email_subject, $email_body, $headers);
?>
Currently when I try to submit an email it says This page isn't working, and is currently unable to handle the request

Contact Form - How to not redirect to another page after submission [duplicate]

This question already has answers here:
Submit form and stay on same page?
(5 answers)
Submit form without reloading or leaving current page (php- mysql)
(2 answers)
How to submit an HTML form without redirection
(12 answers)
Submit form without page reloading
(19 answers)
Stop form refreshing page on submit
(20 answers)
Closed 4 years ago.
I have a contact form that works fine but my issue is it goes to another page if you click submit and echos "Email Sent!"
How can I prevent such redirect? I would like it to just pop under the button, or the button disappears and will be replaced with "Email Sent!" or "Error!"?
Here's my HTML:
<div style="padding-top: 75px; padding-left: 0;" class="col-md-6 col-sm-6 col-xs-12 contact-padding hidden-xs hidden-sm" id="form_container">
<div class="row">
<div class="col-centered1 col-md-8">
<h2 style="font-family: 'yrthree_boldregular', sans-serif;" class="divider-header3">Hit us up</h2>
</div>
</div>
<form role="form" method="post" id="contact-form" action="mail.php" name="contact-form">
<div class="row">
<div class="col-centered1 col-md-8 form-group">
<input type="text" id="name" name="name" class="form-control" placeholder="NAME" required>
</div>
</div>
<div class="row">
<div class="col-centered1 col-md-8 form-group">
<input type="text" id="email" name="email" class="form-control" placeholder="EMAIL" required>
</div>
</div>
<div class="row">
<div class="col-centered1 col-md-8 form-group">
<textarea style="resize: none; border: 0; color: #07002c;" class="form-control" type="text" name="message" id="message" placeholder="MESSAGE" maxlength="6000" rows="7"></textarea>
</div>
</div>
<div class="row">
<div class="col-centered1 col-md-8 form-group">
<a class="btn btn-primary pull-left send-button1" onclick="document.getElementById('contact-form').submit();">
<img draggable="false" src="/images/send-button1.jpg" alt="" onmouseover="this.src='/images/send-button2.jpg';" onmouseout="this.src='/images/send-button1.jpg';">
</a>
</div>
</div>
</form>
</div>
Here's my PHP code:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$content="From: $name \n Email: $email \n Message: $message";
$recipient = "MY#EMAIL.com";
$mailheader = "From: $email \r\n";
mail($recipient, $content, $mailheader) or die("Error!");
echo "Email sent!";
?>
Thank you! :)
You can use ajax to send without redirecting to another page. I read this answer on this. You can write your code something like this:
<script type="text/javascript">
function sendEnquiryform(){
var name=$('#name').val();
var email=$('#email').val();
var message=$('#message').val();
$.post("send_mail.php",'name='+name+'&email='+email'&message='+message,function(result,status,xhr) {
if( status.toLowerCase()=="error".toLowerCase() )
{ alert("An Error Occurred.."); }
else {
//alert(result);
$('#sucessMessage').html(result);
}
})
.fail(function(){ alert("something went wrong. Please try again") });
}
Html:
<form method="post" name="FrmEnquiry" id="FrmEnquiry" action="" onsubmit="sendEnquiryform();">
<input name="name" id="name" required="required" placeholder="Your Name">
<input name="email" id="email" type="email" required="required" placeholder="Your Email">
<div class="clearfix"> </div>
<textarea name="message" id="message" cols="20" rows="5" required="required" placeholder="Message"></textarea>
<div class="submit">
<input id="submit" name="submit" type="submit" value="Submit">
</div>
</form>
<span id="sucessMessage"> </span>
send mail.php
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: agriindiaexp.com';
$to = 'shridhar.kagi#gmail.com';
$subject = 'Email Inquiry';
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
if ($_POST['submit']) {
if (mail ($to, $subject, $body, $from)) {
$success = "Message successfully sent";
} else {
$success = "Message Sending Failed, try again";
}
}
?>
This worked for me. Thanks to the author for answering it.
form action should be blank like
and add php code should be on same page and files ext. should be .php

How to make a div visible after email is sent using PHP

I have the following contact form in my index.html file
<div class="alert alert-success visible" id="successmsg"><strong>Success!</strong> Your message has been sent to us.</div>
<form method="post" action="mail.php" class="contact-form">
<div class="form-group">
<input type="text" class="form-control" name="name" id="name" placeholder="Name">
</div>
<div class="form-group">
<input type="email" class="form-control" name="email" id="email" placeholder="Email">
</div>
<div class="form-group">
<input type="text" class="form-control" name="subject" id="subject" placeholder="Subject">
</div>
<div class="form-group">
<textarea class="form-control" type="text" name="message" id="message" placeholder="Message"></textarea>
</div>
<div class="actions">
<button type="submit" data-text="SUBMIT" class="button button-default"><span>SUBMIT</span></button>
</div>
</form>
The id "successmsg" is hidden in the HTML file using a simple display:none; code & I need to make it visible when the email is sent using the following php
<?php$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$subject = $_POST['subject'];
$formcontent=" Name:\r $name \n\n Email:\r $email \n\n Subject:\r $subject \n\n Message:\r $message ";
$recipient = "towersdvd#gmail.com";
$subject = "Website Contact";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader);
<style type="text/css">#lol{display:yes;}</style>
exit;}?>
This doesn't work at all. Can someone assist me with this? Really appreciate your kind help. Thanks in advance! :)
I think you are using/putting the wrong ID
Please change <style type="text/css">#lol{display:yes;}</style>
TO
<style type="text/css">#successmsg{display:inline;}</style>
Hope this will help.
There isn't any 'yes' value for the display property. Try changing it to {display: block;} or {display: inline;} depending.
Check this link for more info: https://developer.mozilla.org/en-US/docs/Web/CSS/display

php contact form, not receiving emails [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 7 years ago.
please assist with my PHP form. Following this text I have both my HTML form as well as my PHP page described. I am not receiving the e-mails when I attempt to use the form on my website. I have validated that my e-mail address is working, and that should not be the issue.
The following is my HTML form:
<!-- Contact Form -->
<div class="col-md-6 col-sm-6">
<hr>
<p>Have a question or comment? Fill out the form below.</p>
<div class="contact-form wow fadeInLeft showdelay2">
<form name="sentMessage" id="contactForm" novalidate>
<div class="control-group form-group">
<div class="controls">
<label>Name</label>
<input type="text" class="form-control dark" id="name" placeholder="Name" required data-validation-required-message="Please enter your name.">
<p class="help-block"></p>
</div>
</div>
<div class="control-group form-group">
<div class="controls">
<label>Email</label>
<input type="email" class="form-control dark" id="email" placeholder="Email Address" required data-validation-required-message="Please enter your email address.">
<p class="help-block"></p>
</div>
</div>
<div class="control-group form-group">
<div class="controls">
<label>Message</label>
<textarea class="form-control dark" rows="7" id="message" placeholder="Message" required data-validation-required-message="Please enter your message" maxlength="999" style="resize:none"></textarea>
<p class="help-block"></p>
</div>
</div>
<div id="success"></div>
<div class="pull-right">
<button type="submit" class="btn btn-info btn-lg">Submit</button>
</div>
</form>
<div class="clearfix"></div>
</div>
</div>
<!-- ./contact form -->
The following code is my contact_me.php page, which doesn't appear to be working.
<?php
// check if fields passed are empty
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['message']) ||
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
echo "No arguments Provided!";
return false;
}
$name = $_POST['name'];
$email_address = $_POST['email'];
$message = $_POST['message'];
// create email body and send it
$to = 'email#addresss.com'; 'email#address.com'; // PUT YOUR EMAIL ADDRESS HERE
$email_subject = "Contact form from: $name"; // EDIT THE EMAIL SUBJECT LINE HERE
$email_body = "You have received a new message from your website's contact form.\n\n"."Here are the details:\n\nName: $name\n\nEmail: $email_address\n\nMessage:\n$message";
$headers = "From: info#bootstrapwizard.info\n";
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
return true;
?>
your to string is incorrect, the valid format is:
$to = 'AdrianPham#crosshatcheatery.com,Webmaster#crosshatcheatery.com';
the headers should end with "\r\n"
$headers = "From: info#bootstrapwizard.info\r\n";
$headers .= "Reply-To: $email_address";

Cannot POST /.php file when submitting form for email

I'm trying to get a HTML from to work together with PHP in order to make a form for sending a mail, but after submitting the form, PHP file is saying
Cannot POST /quotation.php
Here is my HTML code
<div id="quotation" class="reveal-modal" data-reveal>
<a class="close-reveal-modal">×</a>
<h3>Request Quotation</h3>
<p>Please fill out this information and we will contact you as soon as possilble.</p>
<form method="post" name="" action="quotation.php">
<div class="row">
<div class="large-6 columns">
<label>Name
<input type="text" name="name" placeholder="Name" />
</label>
</div>
<div class="large-6 columns">
<label>Lastname
<input type="text" name="lastname" placeholder="Lastname" />
</label>
</div>
</div>
<div class="row">
<div class="large-6 columns">
<label>Company name
<input type="text" name="company" value="" placeholder="Your company">
</label>
</div>
<div class="large-6 columns">
<label>E-mail
<input type="text" name="email" value="" placeholder="E-mail">
</label>
</div>
</div>
<div class="row">
<div class="large-12 columns">
<label>Additional details
<textarea name="message" placeholder="Additional details here"></textarea>
</label>
</div>
</div>
<input class="button radius" type="submit" name='submit' value="submit">
</form>
</div>
And this is the PHP that runs the form
<?php
if(!isset($_POST['submit']))
{
//This page should not be accessed directly. Need to submit the form.
echo "error; you need to submit the form!";
}
$name = $_POST['name'];
$lastname = $_POST['lastname'];
$company = $_POST['company'];
$visitor_email = $_POST['email'];
$message = $_POST['message'];
$email_from = $visitor_email;//<== update the email address
$email_subject = "New Form submission";
$email_body = "You have received a new message from the user $name, $lastname.\n".
"Here is the message:\n $message".
$to = "email#gmail.com";
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
//Send the email!
mail($to,$email_subject,$email_body,$headers);
echo "Mail Sent. Thank you " . $name . ", we will contact you shortly.";
alert("yo");
//done. redirect to thank-you page.
header('Location: index.html');
?>
I added alert and echo for submit button, but none of them appears so looks like PHP is not even running.
It would be great if someone could guide me trough this problem or point out what am I doing wrong.

Categories