This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 5 years ago.
I am absolutely bad at PHP programming. I have no experience with it, but I wanted a form on my website with a mail script. So like almost every other person with no experience on a language, I googled up one and customized it.
mail_send.php
<?php
if(isset($_POST['submit'])){
$to = "my#mailadress.com"; // I just did this for privacy
$from = $_POST['email'];
$name = $_POST['name'];
$subject = "Form submission";
$message = $name . " " . $from . " wrote the following:" . "\n\n" .
$_POST['message'];
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent. Thank you " . $name . ", we will contact you shortly.";
}
?>
and here the HTML code: index.html
<form role="form" id="feedbackForm" class="text-center" action="mail_send.php" method="post">
<div class="form-group">
<label for="name">Naam</label>
<input type="text" class="form-control" id="name" name="name" placeholder="Name">
<span class="help-block" style="display: none;">Voer uw naam in..</span></div>
<div class="form-group">
<label for="email">E-Mail</label>
<input type="email" class="form-control" id="email" name="email" placeholder="Email Address">
<span class="help-block" style="display: none;">Voer een geldig e-mailadres in.</span></div>
<div class="form-group">
<label for="message">Bericht</label>
<textarea rows="10" cols="100" class="form-control" id="message" name="message" placeholder="Message"></textarea>
<span class="help-block" style="display: none;">Voer een bericht in.</span></div>
<button type="submit" id="feedbackSubmit" class="btn btn-primary btn-lg" style=" margin-top: 10px;"> Verstuur</button>
</form>
So I have uploaded both files to my Website Server so I've tested it online, but still without success. Any smart guys being able to help me?
Thanks in advance :)
Please modify button tag
<button type="submit" name="submit" id="feedbackSubmit" class="btn btn-primary btn-lg" style=" margin-top: 10px;"> Verstuur</button>
I suggest to do not use mail function directly. Better use something like https://github.com/PHPMailer/PHPMailer and use it through SMTP of a real e-mail account of yours.
You are checking in your IF clause $_POST['submit'] - But I don't see where did you set this name="submit" in your html code... you need to add name="submit" to your button
Use name = submit in button tag.
<button type="submit" name="submit" id="feedbackSubmit" class="btn btn-primary btn-lg" style=" margin-top: 10px;"> Verstuur</button>
After that also check your spam folder. Sometime you don't get messages in inbox.
Modify as per your requirement and I hope this code will send you message to inbox directly rather than span
<?php
if(isset($_POST['submit'])){
$to = "Email Address Here"; // I just did this for privacy
$from = $_POST['email'];
$name = $_POST['name'];
$subject = "Form submission";
$message = $name." ".$from." wrote the following:". "\n\n". $_POST['message'];
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: <info#example.com>' . "\r\n";
mail($to,$subject,$message,$headers);
echo "Mail Sent. Thank you " . $name . ", we will contact you shortly.";
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Mail Example</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<form role="form" id="feedbackForm" class="text-center" action="" method="post">
<div class="form-group">
<label for="name">Naam</label>
<input type="text" class="form-control" id="name" name="name" placeholder="Name">
<span class="help-block" style="display: none;">Voer uw naam in..</span></div>
<div class="form-group">
<label for="email">E-Mail</label>
<input type="email" class="form-control" id="email" name="email" placeholder="Email Address">
<span class="help-block" style="display: none;">Voer een geldig e-mailadres in.</span></div>
<div class="form-group">
<label for="message">Bericht</label>
<textarea rows="10" cols="100" class="form-control" id="message" name="message" placeholder="Message"></textarea>
<span class="help-block" style="display: none;">Voer een bericht in.</span></div>
<button type="submit" name="submit" id="feedbackSubmit" class="btn btn-primary btn-lg" style=" margin-top: 10px;"> Verstuur</button>
</form>
</body>
</html>
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 am using Ampps on Mac and trying to send an email using php from a contact form however I do not receive the mail and when the form is submitted it redirects me to the file page resulting in a blank display
my form :
<form action="email.php" method="post">
<div class="col-md-6 w3_agileits_contact_left">
<span class="input input--akira">
<input class="input__field input__field--akira" type="text" id="input-22" name="Name" placeholder="" required="" />
<label class="input__label input__label--akira" for="input-22">
<span class="input__label-content input__label-content--akira">Your name</span>
</label>
</span>
<span class="input input--akira">
<input class="input__field input__field--akira" type="email" id="input-23" name="Email" placeholder="" required="" />
<label class="input__label input__label--akira" for="input-23">
<span class="input__label-content input__label-content--akira">Your email</span>
</label>
</span>
<span class="input input--akira">
<input class="input__field input__field--akira" type="text" id="input-24" name="Subject" placeholder="" required="" />
<label class="input__label input__label--akira" for="input-24">
<span class="input__label-content input__label-content--akira">Your subject</span>
</label>
</span>
</div>
<div class="col-md-6 w3_agileits_contact_right">
<div class="w3_agileits_contact_right1">
<textarea name="Message" id="Message" placeholder="Your comment here..." required=""></textarea>
</div>
<div class="w3_agileits_contact_right2">
<input type="submit" value="Send">
</div>
<div class="clearfix"> </div>
</div>
<div class="clearfix"> </div>
</form>
my File :
$email = $_POST['Email'];
$name = $_POST['Name'];
$to = "lucvanrooyen#gmail.com";
$subject = $_POST['Subject'];
$userMessage =$_POST['Message'];
$headers = "From: $email\n";
$message = "$name has sent you the following message.\n
Message: $userMessage";
$user = "$email";
$usersubject = "Thank You";
$userheaders = "From: lucvanrooyen#gmail.com\n";
$usermessage = "Thank you for your enquiry we will be in touch.";
mail($to,$subject,$message,$headers);
mail($user,$usersubject,$usermessage,$userheaders);
The code you have shown is not enough to debug your problem.
If you are using the mail method which is built into the standard library, read this answer to find out a few troubleshooting steps you could follow.
If you are and are still finding it difficult to use, then you could consider using one of the PHP emailing solutions like -
PHPMailer
SwiftMailer
Please check your form tag. there is no opening tag for form
<form action="email.php" method="post">
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 5 years ago.
HTML Codes
<h3>online consultation</h3>
<h5>We have provided contact information down below. You can contact us either by mobile, via email or via contact form. We will at once contact you to discuss your problems! If you have special requirments a consultation can be decided.</h5>
</div>
<div class="col-md-7 col-lg-offset-3 contact-grid-right">
<form method="post" action="mail.php">
<input type="text" placeholder="Your Name" name="name" id="name" required="required">
<input type="text" placeholder="Email" name="Email" id="Email" required="required">
<input type="text" placeholder="Contact No" name="contact" id="contact" required="required">
<input type="text" placeholder="Subject" name="subject" id="subject" required="required">
<textarea rows="2" cols="70" type="text" placeholder="MESSAGE" name="message" id="message" required="required">
</textarea>
<button type="submit" class="slide-btn"> Send your message <i class="fa fa-paper-plane" aria-hidden="true"></i> <br></button>
</form>
</div>
PHP Script
<?php
$n=$_POST['name'];
$mail=$_POST['email'];
$ph=$_POST['contact'];
$ln=$_POST['subject'];
$msg=$_POST['message'];
$to="email#yahoo.com";
$sub="message";
$body="
<html>
<body>
<p><b></b></p><h4></h4>
<table border='0'>
<tr>
<b>Name : </b> $n <br><br>
<b>Email : </b> $mail <br><br>
<b>Contact :</b> $ph <br><br>
<b>Subject :</b> $ln <br><br>
<hr>
<b>Contact Form Message:</b> <br><br>$msg
</tr>
</table>
</body>
</html>";
$headers = "MIME-Version: 1.0". "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8". "\r\n";
$headers .= 'From:'.$mail . "\r\n";
//$headers .= 'Cc: email#yahoo.com.au'; "\r\n";
//$headers .= 'Bcc: '; "\r\n";
mail($to,$sub,$body,$headers);
//echo "<script>alert('Message Send Sucessfully')</script>";
echo "<script>window.location.href='index.html'</script>";
?>
here the solution change the $mail=$_POST['email']; in your php script to $mail=$_POST['Email'];
For keeping your code standard replace the email html input for:
<input type="text" placeholder="Email" name="email" id="email" required="required">
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 5 years ago.
I haven't written code in years, so I am going off old code from a project that is over 5 years old, so I am not surprised that it doesn't work; I would like some pointers on how to make it work, please.
Here is what I have in my HTML email form --
<form action="fydcontact.php" method="post">
<div class="form-group">
<!--<label for="contact_name">Name:</label>-->
<input type="text" id="contact_name" class="form-control" placeholder="Name" />
</div>
<div class="form-group">
<!--<label for="contact_email">Email:</label>-->
<input type="text" id="contact_email" class="form-control" placeholder="Email Address" />
</div>
<div class="form-group">
<!--<label for="contact_message">Message:</label>-->
<textarea id="contact_message" class="form-control" rows="9" placeholder="Write a message"></textarea>
</div>
<button type="submit" class="btn btn-primary">Send</button>
</form>
and here is what my PHP looks like --
<?php
if(isset($_POST['send'])) {
// Prepare the email
$to = ''foryourdayformals#gmail.com ';
$name = $_POST['contact_name'];
$mail_from = $_POST['contact_email'];
$subject = 'Message sent from website';
$message = $_POST['contact_message'];
$header = "From: $name <$mail_from>";
// Send it
$sent = mail($to, $subject, $message, $header);
if($sent) {
echo 'Your message has been sent successfully! Return to For Your Day, LLC Website';
} else {
echo 'Sorry, your message could not send. Please use direct email link on Contact Us page (below the map). Return to For Your Day, LLC Website';
}
}
?>
Any help is GREATLY appreciated! Thanks!
update
$to = ''foryourdayformals#gmail.com ';
to
$to = 'foryourdayformals#gmail.com';
and need to add name attribute for form . This update your form
<form action="fydcontact.php" method="post">
<div class="form-group">
<!--<label for="contact_name">Name:</label>-->
<input type="text" id="contact_name" name="contact_name" class="form-control" placeholder="Name" />
</div>
<div class="form-group">
<!--<label for="contact_email">Email:</label>-->
<input type="text" id="contact_email" name="contact_email" class="form-control" placeholder="Email Address" />
</div>
<div class="form-group">
<!--<label for="contact_message">Message:</label>-->
<textarea id="contact_message" name="contact_message" class="form-control" rows="9" placeholder="Write a message"></textarea>
</div>
<button type="submit" class="btn btn-primary" name ="send">Send</button>
</form>
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