Contact form error dose not send email [duplicate] - php

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
How do you make sure email you send programmatically is not automatically marked as spam?
(24 answers)
Closed 5 years ago.
i am facing a problem in contact form it gets validated successfully and i get the Jquery response " your email has been sent successfully" but the problem is the email dosen't get delivered. i am pasting the code here please help me. its an html based site but.
CONTACT FORM.HTML
<!-- contact-area start -->
<div class="contact-area ptb-120 bg-2">
<div class="container">
<div class="row">
<div class="col-md-4 col-xs-12">
<div class="contact-wrap">
<h3>CONTACT INFO</h3>
<p>#123 King , Melbourne vic 3000, Sydney New City, Australia</p>
<p>(+08) 9673 123 765,(+08) 9673 148 112</p>
<p>hello#university.com</p>
</div>
</div>
<div class="col-md-8 col-xs-12">
<div class="contact-form">
<div class="cf-msg"></div>
<form action="mail.php" method="post" id="cf">
<div class="row">
<div class="col-md-6 col-sm-6 col-xs-12">
<input type="text" placeholder="Name" id="fname" name="fname">
</div>
<div class="col-md-6 col-sm-6 col-xs-12">
<input type="text" placeholder="Email" id="email" name="email">
</div>
<div class="col-md-12 col-sm-12 col-xs-12">
<input type="text" placeholder="Subject" id="subject" name="subject">
</div>
<div class="col-md-12 col-sm-12 col-xs-12">
<textarea class="contact-textarea" placeholder="Message" id="msg"
name="msg"></textarea>
</div>
<div class="col-md-12 col-sm-12 col-xs-12">
<button id="submit" class="cont-submit btn-contact" name="submit">Submit
A Message</button>
</div>
</div>
</form>
MAIL.PHP
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
//Taking all values
$to = "shijumax#gmail.com";
$fname = $_POST['fname'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$msg = $_POST['msg'];
$output = "Name: ".$fname."\n\nSubject: ".$subject."\n\nMessage:
".$msg;
$headers = 'FROM: "'.$email.'"';
$send = mail($to, $fname, $output."\n\n***This message has been
sent from me", $headers);
$body = "Name: ".$fname."\n E-Mail: $email\n Message:\n $msg";
echo "Data has been submitted to $to!";
mail($to, $subject, $body);
}
?>

Related

PHP - html form sent to gmail account

I never used PHP before, but I need to set up an HTML form from to be sent from my website to my gmail account. Checked some tutorials and came up with this code. But for some reason it is not working. When I hit submit it goes to a "Page Not Found
Looks like you've followed a broken link or entered a URL that doesn't exist on this site." Not sure what am I doing wrong.
I have my HTML document, and I have my PHP document. Saved together.
<form action="contact.php" method="POST" name="form">
<div class="row">
<div class="col-12 col-md-6">
<div class="contact-form">
<label for="name">Please enter your name:</label>
<input name="name" type="text" class="form-control" placeholder="Harry Potter">
</div>
</div>
<div class="col-12 col-md-6">
<div class="contact-form">
<label for="mail">Your email address:</label>
<input name="mail" type="email" class="form-control" placeholder="harry#potter.com">
</div>
</div>
</div>
<div class="row">
<div class="col-12">
<div class="contact-form">
<label for="message">How can I help you?</label>
<textarea name="message" class="form-control" id="form-text" cols="30" rows="10" placeholder="Let's do some magic"></textarea>
</div>
</div>
</div>
<div id="submit" class="text-center">
<button name="submit" type="submit" class="btn mt-5 mx-auto">Submit</button>
</div>
</form>
<?php
if(isset($_POST["submit"])) {
$name=$_POST["name"];
$mailFrom=$_POST["mail"];
$message=$_POST["message"];
$mailTo = "myaddress#gmail.com";
$subject = "Form from my website";
$headers = "From: ".$mailFrom;
$txt = "You have received an e-mail from ".$name."\n\n".$message;
if(mail($mailTo, $subject, $txt, $headers)) {
echo "<h1>I recieved your email! Will be in touch with you soon.</h1>";
}
else{
echo "<h1>Something went wrong! Try again.</h1>";
}
header("Location: https://www.whatever.com");
}
?>

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

405 Not Allowed error when submitting html form to php file [duplicate]

Having an issue with getting data from a form that I created and passing it into my email through php. Here's the link with the form http://kapena.github.io/pp_web/#contact-pp
Here's the exact issue..
When I click submit on the form button I get this error message saying..
I'm currently hosting this build on a gh-pages
I did some research on this and I found a patch for the error 405 but I have no idea how to implement this solution into my project. I am just a beginner and I need some instruction..Here's the solution I found https://gist.github.com/baskaran-md/e46cc25ccfac83f153bb#file-nginx-conf
How can I implement this solution correctly into my site?
Here's my php code so you can inspect that to see if there's and issue there thats causing this problem.
Any help would be greatly appreciated here..Trying to launch b4 the new year :)
<?php
if($_POST["submit"]) {
$recipient = "brentw.white#gmail.com"; //my email
$subject = 'Email message from Point Plumbing';
$name = $_POST ["yourName"];
$email = $_POST["yourEmail"];
$phone = $_POST["yourPhone"];
$location = $_POST["yourLocate"];
$message = $_POST["message-me"];
$mailBody="Name: $name\nEmail: $email\n\n$message";
$mail($recipient, $subject, $mailBody, "From: $name <$email>");
$thankYou="<p>Thank you! We will be in contact with you shortly.</p>";
}
?>
My HTML..I have a feeling it has something to do with method='post' possible that's the issue?
<form action="submit_form.php" method="post" id="spaceing" data-abide>
<div class="form-bg">
<div class="row">
<div id="name" class="large-6 medium-6 small-12 columns">
<label> <h5>Name</h5>
<input type="text" name="yourName" placeholder="What is you're name?"></input>
</label>
</div>
<div id="email" class="large-6 medium-6 small-12 columns">
<label><h5>Email</h5>
<input type="email" name="yourEmail" placeholder="Please enter in you're email."required></input>
</label>
<small class="error">An email Address is required.</small>
</div>
</div>
<div class="row">
<div id="phone"class="large-6 medium-6 small-12 columns">
<label><h5>Phone</h5>
<input type="text" name="yourPhone" placeholder="Please enter you're phone number."></input>
</label>
</div>
<div id="location" class="large-6 medium-6 small-12 columns">
<label><h5>Location</h5>
<input type="text" name="yourLocate" placeholder="Where on Oahu are you currently living?"></input>
</label>
</div>
</div>
<div class="row">
<div id="message-area" class="large-12 medium-12 small-12 columns">
<label><h5>Message</h5>
<textarea id="message" name="yourMessage" placeholder="Please tell us about you're plumbing issues."></textarea>
</label>
</div>
</div>
<div class="row">
<div id="submit" class="large-3 medium-3 small-3 columns">
<button type="submit-me">Submit</button>
</div>
</div>
</div>
</form>
look http://php.net/manual/en/function.mail.php
$mail($recipient, $subject, $mailBody, "From: $name <$email>");
$mail is not variable is function then
mail($recipient, $subject, $mailBody, "From: $name <$email>");
I modified your code and find lots of error.correct code is below:-
found following error on your code
1. use if(isset($_POST["submit"])) { instead of if($_POST["submit"]) {
2. you use wrong variable name for textarea. you should use $message = $_POST["yourMessage"]; instead of $message = $_POST["message-me"];
4. another error is your form action is at submit_form.php page but i found your mail code is at top of your page. if you want to submit to another page then use php code to submit_form.php page.
5. Main and important error of your code i found you using your gmail email at the place of sending mail.but you should use your domain email like brentw.white#kapena.github.io if you using another domain email these mail are count as suspicious and your mail goes to spam
I think it will be help full for you
I used your link here:-
http://smartzonewebservices.com/mtg/del.php
<?php
if(isset($_POST["submit"])) {
$recipient = "brentw.white#gmail.com"; //my email
echo $subject = 'Email message from Point Plumbing';
echo $name = $_POST ["yourName"];
echo $email = $_POST["yourEmail"];
echo $phone = $_POST["yourPhone"];
echo $location = $_POST["yourLocate"];
echo $message = $_POST["yourMessage"];
$mailBody="Name: $name\nEmail: $email\n\n$message";
mail($recipient, $subject, $mailBody, "From: $name <$email>");
echo $thankYou="<p>Thank you! We will be in contact with you shortly.</p>";
}
?>
<form action="" method="post" id="spaceing" data-abide>
<div class="form-bg">
<div class="row">
<div id="name" class="large-6 medium-6 small-12 columns">
<label> <h5>Name</h5>
<input type="text" name="yourName" placeholder="What is you're name?"></input>
</label>
</div>
<div id="email" class="large-6 medium-6 small-12 columns">
<label><h5>Email</h5>
<input type="email" name="yourEmail" placeholder="Please enter in you're email."required></input>
</label>
<small class="error">An email Address is required.</small>
</div>
</div>
<div class="row">
<div id="phone"class="large-6 medium-6 small-12 columns">
<label><h5>Phone</h5>
<input type="text" name="yourPhone" placeholder="Please enter you're phone number."></input>
</label>
</div>
<div id="location" class="large-6 medium-6 small-12 columns">
<label><h5>Location</h5>
<input type="text" name="yourLocate" placeholder="Where on Oahu are you currently living?"></input>
</label>
</div>
</div>
<div class="row">
<div id="message-area" class="large-12 medium-12 small-12 columns">
<label><h5>Message</h5>
<textarea id="message" name="yourMessage" placeholder="Please tell us about you're plumbing issues."></textarea>
</label>
</div>
</div>
<div class="row">
<div id="submit" class="large-3 medium-3 small-3 columns">
<button name="submit" type="submit">Submit</button>
</div>
</div>
</div>
</form>
I thing this going because you develop on github server and he does not allow make POST
change your code HTML:
<form action="submit_form.php" method="get" id="spaceing" data-abide>
and PHP change $_POST for $_GET but there is problem with length because all data is sending in URL.
If you want public page to normal server return back to POST method

PHP POST / Bootstrap Form

Im not receiving emails from my email form.
I created a simple form that takes 4 fields and sends them to our emails. I tested my php code with no errors. I double checked the html to see if the script was referring properly which it was. I believe that the ids and names are correct. I also triple checked the variables I created on the php code. I've googled everything I could come up with no luck. Thanks!
var dump $body shows
Thank you! One of our station representatives will contact you soon.
string(119) "
Name: TEST
Email: test#emaol.com
Station: 1234
Message:
I need help with.
FORM
<form class="form-horizontal" role="form" method="post" action="feedback.php">
<fieldset>
<!-- Form Name -->
<legend>Our team will reach out to you as soon as possible.</legend>
<!-- Text input-->
<div class="control-group col-xs-4">
<label class="control-label" for="textinput">Full Name</label>
<div class="controls">
<input id="name" name="name" placeholder="John Doe" class="input-xlarge" type="text">
</div>
</div>
<!-- Text input-->
<div class="control-group col-xs-4">
<label class="control-label" for="textinput">E-Mail</label>
<div class="controls">
<input id="email" name="email" placeholder="affiliate.marketing.app#123.com" class="input-xlarge" type="text">
</div>
</div>
<!-- Text input-->
<div class="control-group col-xs-4">
<label class="control-label" for="textinput">Station Code</label>
<div class="controls">
<input id="station" name="station" placeholder="xxx" class="input-xlarge" type="text">
</div>
</div>
<!-- Textarea -->
<div class="control-group">
<label class="control-label" for="textarea">Message</label>
<div class="controls">
<textarea id="message" name="message">I need help with....</textarea>
</div>
</div>
<!-- Button -->
<div class="control-group">
<label class="control-label" for="submit"></label>
<div class="controls">
<button type="submit" id="submit" value="Send" name="singlebutton" class="btn btn-primary">Submit</button>
</div>
</div>
</fieldset>
</form>
PHP PAGE
<?php
/* These are the variable that tell the subject of the email and where the email will be sent.*/
$emailSubject = 'Station App Support Request';
$mailto = 'myemail#domain.com, myemail2#domain.com';
/* These will gather what the user has typed into the fieled. */
$nameField = $_POST['name'];
$emailField = $_POST['email'];
$stationField = $_POST['station'];
$messageField = $_POST['message'];
/* This takes the information and lines it up the way you want it to be sent in the email. */
$body = <<<EOD
<br><hr><br>
Name: $nameField <br>
Email: $emailField <br>
Station: $stationField <br>
Message: $messageField <br>
EOD;
$headers = "From: $emailField\r\n"; // This takes the email and displays it as who this email is from.
$headers .= "Content-type: text/html\r\n"; // This tells the server to turn the coding into the text.
$success = mail($mailto, $emailSubject, $body, $headers); // This tells the server what to send.
?>

Trouble with PHP sending emailing from contact form

I have a site up and running and cant seem to get the php to send the form data. Get thank you message sometimes but never appears in mail. my aim is to have the form collect the data then email the data to the client.
Thanks for any help. I am struggling to get to grips with php it would appear.
<?php
$to = "********#*******.com";
$subject = "Contact Us";
$email = $_REQUEST['email'] ;
$message = $_REQUEST['enquiry'] ;
$headers = "From: $email";
$sent = mail($to, $subject, $message, $headers) ;
if($sent)
{print "Your mail was sent successfully";}
else
{print "We encountered anerror sending your mail";}
?>
<section class="container">
<section class="col-lg-6 col-lg-offset-1">
<form class="form-horizontal text-center" role="form" method="post" action="form_send.php">
<div class="form-group">
<label for="Name" class="col-lg-2 control-label">Name:</label>
<div class="col-lg-6">
<input type="name" class="form-control" id="name" name="name" placeholder="Enter Name...">
</div>
</div>
<div class="form-group">
<label for="Email" class="col-lg-2 control-label">Email:</label>
<div class="col-lg-6">
<input type="email" class="form-control" id="email" name="email" placeholder="Enter Email...">
</div>
</div>
<div class="form-group">
<label for="Phone" class="col-lg-2 control-label">Phone:</label>
<div class="col-lg-6">
<input type="phone" class="form-control" id="phone" placeholder="Enter Phone Number...">
</div>
</div>
<div class="form-group">
<label for="Enquiry" class="col-lg-2 control-label">Enquiry:</label>
<div class="col-lg-6">
<textarea type="enquiry" class="form-control" rows="5" id="enquiry" name="enquiry" placeholder="Enter Email..."></textarea>
</div>
</div>
<div class="form-group">
<label for="Enquiry" class="col-lg-2 control-label"></label>
<div class="col-lg-6">
<button class="btn btn-primary" type="submit">Send Message</button>
</div>
</div>
</form>
Reply from email server:
Technical details of permanent failure: Google tried to deliver your message, but it was rejected by the server for the recipient domain peoplespropertyshop.co.uk by aspmx.l.google.com. [2607:f8b0:4003:c02::1a]. The error that the other server returned was: 550-5.1.1 The email account that you tried to reach does not exist. Please try 550-5.1.1 double-checking the recipient's email address for typos or 550-5.1.1 unnecessary spaces. Learn more at 550 5.1.1 support.google.com/mail/bin/answer.py?answer=6596 t6si822722oei.44 - gsmtp
First you should check that your code is in one file (form_send.php). After that add some check if user have submitted the form:
if (!empty($_POST))
Message is sent to $to email. If you want to change that, pass $email paramter to mail() function:
$sent = mail($to, $subject, $message, $headers) ;
to:
$sent = mail($email, $subject, $message, $headers);
Also check your mail server configuration and add some validation.
$email = htmlentities($_REQUEST['email']);
$message = htmlentities($_REQUEST['enquiry']);

Categories