This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 5 years ago.
I have a problem with my contact form that I have created. When the user clicks on the send email button, I receive the email with a header, but I can't see the user's input.
So basically I am able to see the header($subject) and the pre written text("This is an automated message"), but I am not able to see the contents of $email and $message. What could be wrong?
<?php
$email = $_POST['email'];
$message = $_POST['message'];
$to = "test#testemail.com";
$subject = "New Message!"; $body = "This is an automated message. Please do not reply to this email. \n\n $email \n\n $message";
mail($to, $subject, $body); echo "Message Sent.";
?>
<form id="contact-me-form" action="contact.php" name="contact_form "method="post">
<input type="text" name="email" placeholder="Email Address">
<textarea name="message" placeholder="Type Your Message Here"></textarea>
<input id="sendEmail" type="submit" name="submit" value="Send">
</form>
you need to check whether you have post parameters then send the email
change your code to
<?php
if(isset($_POST['email']) && isset($_POST['message'])){
$email = $_POST['email'];
$message = $_POST['message'];
$to = "test#testemail.com";
$subject = "New Message!"; $body = "This is an automated message. Please do not reply to this email. \n\n $email \n\n $message";
mail($to, $subject, $body); echo "Message Sent.";
}
?>
<form id="contact-me-form" action="contact.php" name="contact_form "method="post">
<input type="text" name="email" placeholder="Email Address">
<textarea name="message" placeholder="Type Your Message Here"></textarea>
<input id="sendEmail" type="submit" name="submit" value="Send">
</form>
Try like this
<?php
$email = $_POST['email'];
$message = $_POST['message'];
$to = "test#testemail.com";
$subject = "New Message!"; $body = "This is an automated message. Please do not reply to this email. \n\n $email \n\n $message";
$body= $_POST["message"]
if ($_SERVER["REQUEST_METHOD"] == "POST") {
mail($to, $subject, $body); echo "Message Sent.";
}
?>
<form id="contact-me-form" action="contact.php" name="contact_form "method="post">
<input type="text" name="email" placeholder="Email Address">
<textarea name="message" placeholder="Type Your Message Here"></textarea>
<input id="sendEmail" type="submit" name="submit" value="Send">
</form>
This will send an email to test#testemail.com when the user submit a message in the form
Related
When using a html form to call php to send an email with the details in the form to an email address specified in the php. The php file name is added to the URL but no email is sent and the page shown in blank.
The website is being hosted on my.ionos.co.uk (1&1) using php 7.3.
<form method="post" action="contact-form.php">
<input class="contact" type="text" name="Name" placeholder="Name">
<input class="contact" type="text" name="Email" placeholder="Your Email Address">
<input class="contact" type="text" name="Subject" placeholder="Subject">
<textarea class="contact" name="Message" rows="10" placeholder="Message"></textarea>
<input class="contact-submit" type="submit" value="Send Message">
</form>
<?php
if(isset($_POST['submit'])) {
$name = $_POST['Name'];
$mailFrom = $_POST['Email'];
$subject = $_POST['Subject'];
$message = $_POST['Message'];
$mailTo = "X#hotmail.com";
$headers = "From: ".$mailFrom;
$txt = "You have recieved an email from ".$name.".\n\n".$Message;
if(mail($mailTo, $subject, $txt, $headers)){
echo "<h1>Mail send successfully</h1>";
} else {
echo "<h1>Mail failed to send<h1>";
}
header("Location: contact.html?mailsend");
}
?>
I'd appreciate it if someone could help, thanks in advance!
Try to change:
if(isset($_POST['submit'])) {
with
if(isset($_POST['Email'])) { //or another field in your form. If you want you can also add in your submit button: name="submit"
Checking out your code seems there is not an input with name submit. So you never enter in the if case.
I am trying to power my contact form with the following HTML and PHP, and when I enter information and press enter, I always get an Error!
HTML
<form action="contact.php" method="POST">
<input type="text" placeholder="your name" name="name">
<input type="email" placeholder="Your Email" name="email">
<textarea placeholder="Your Message" name="message"></textarea>
<button type="submit">submit</button>
</form>
PHP
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent=" From: $name \n Email: $email \n Message: $message";
$recipient = "jainkenul#gmail.com";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!";
?>
I have uploaded these files on my server, you can check it here
I don't see any error in your code. Probably, your host may have disabled the mail() function
I am attempting to send the details in the fields of a contact form to my mail id. I dont seem to be getting any errors when I hit
submit but I am not receiving any mail.
Here is my code
<?PHP
$email = $_POST["email"];
$to = "myemail#example.com";
$subject = "New Email Address for Mailing List";
$headers = "From: $email\n";
$message = "A visitor to your site has sent the following details to you.\n
Name : $name
Email Address: $email
Phone number: $phone
Message: $message";
$user = "$email";
$usersubject = "Thank You";
$userheaders = "From: myemail#example.com\n";
$usermessage = "Thank you for contacting us.";
mail($to,$subject,$message,$headers);
mail($user,$usersubject,$usermessage,$userheaders);
?>
<form id="contact-form" class="contact-form" action="contact-form-info.php" enctype="text/plain" >
<div id="result" class="result"></div>
<input type="text" name="name" id="name" placeholder="Name *">
<input type="text" name="email" id="email" placeholder="E-mail *">
<input type="text" name="phone" id="phone" placeholder="Phone *" onChange="PhoneValidation(this)" ;>
<textarea cols="5" rows="5" name="message" id="message" placeholder="Message *"></textarea>
<input type="submit" class="btn-dark" value="SEND">
Your form is:
Encoding the data as text/plain, which isn't machine readable
Sending the data as GET not POST (which is what you are trying to read)
Remove the enctype attribute and add method="POST"
You are also never assigning values to $name or $phone.
I have created a PHP contact form on my site which works well except to see the Success or Error message it sends users to a the thank-you.php page. That is how I have it set up but I want users to submit and the form should dissapear and say Thank You! in place of the form.
Here is my HTML for the form:
<form class="form-foot" action="thank-you.php" method="post">
<fieldset>
<legend>Footer contact form</legend>
<div class="field">
<label for="name">Your name: </label>
<input name="name" id="name" type="text" placeholder="Name" class="required field-name" required>
</div>
<div class="field">
<label for="email">Your email: </label>
<input name="email" id="email" type="email" placeholder="Email address" class="required field-email" required>
</div>
<div class="field">
<label for="message">Message: </label>
<textarea name="message" id="message" cols="30" rows="8" class="required field-message" placeholder="Your message" required></textarea>
</div>
<div class="field-submit">
<input class="sendbutton" type="submit"/>
</div>
</fieldset>
</form>
And here is my PHP in the thank-you.php page:
<?php $name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From: $name \n Message: $message";
$recipient = "myemail#mysite.com";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!";
?>
How can I make the form disappear on submission and echo the Thank You success message without going to thank-you.php or refreshing the page.
Thanks
Replace:
<form class="form-foot" action="thank-you.php" method="post">
with:
<form name="myform" class="form-foot" action="" method="post">
Give a name to your submit button:
<input name="submit" class="sendbutton" type="submit"/>
Move the code from thank-you.php to yourform.php:
if(isset($_POST['submit']))
{
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From: $name \n Message: $message";
$recipient = "myemail#mysite.com";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!";
}
you can use ajax to post data to the thank-you.php file, from javascript. by calling a function on submit instead of the action attribute in the form. the function can have the below format
var url = "thank-you.php";
var data = $('#your-form-id').serialize();
$.ajax({
type: "post",
url: url,
data: data,
success: function(msg) {
}
});
On getting the message from the thank-you page you can make use of it to assign it the html containing the form to replace the form with thank you!
i have a form that work with jquery this form is :
download link for this is
http://www.4shared.com/rar/qkIP2Ulb/magical-contact-form.html
<form class="fcf-contact-form" action="mail.php" method="post">
<div class="right">
<input type="text" name="name" id="name" class="input">
<input type="text" name="email" id="email" class="input">
<div class="left">
<textarea name="message" cols="0" rows="5" class="textarea"></textarea>
<input type="submit" name="submit" value="Send message !" class="submit"/>
</div>
</div>
</form>
and mail.php file code is that code :
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['message'];
$formcontent=" From: $name \n Phone: $phone \n email: $email \n message: $message";
$recipient = "milad.esmailzade#yahoo.com";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "<a href='your page link here.php' style='text-decoration:none;color:#ff0099;'></a>";
?>
i upload this contact form on the host and when i click send i dont recieve email from this form !
what is the problem ?
You have to ask your hosting technical support why the PHP mail function does not work?
Try setting SMTP and user parameters, like this:
ini_set("SMTP","mail.mydomain.com" ); // or the IP
ini_set('sendmail_from', 'Me#mydomain.com'); // Account used to deliver the messages.