Contact form error on sending messages [duplicate] - php

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 6 years ago.
My contact form doesn't send messages.
There are no errors reported in validation so i get the "message sent", but message is not actually sent. So propably there is an error on configuring my mail settings
Here is my code:
HTML:
<div class="container">
<div class="row">
<div class="col-lg-12 text-center">
<h2 class="section-heading middle_heading">Contact Us</h2>
<div class="colored-line2"></div>
<p class="populer_des"></p>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<form class="bg_field" name="sentMessage" action="./mail/validateform.php" method="post" id="contactForm" novalidate>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<input type="text" class="form-control" placeholder="Your Name *" id="name" required data-validation-required-message="Please enter your name.">
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<input type="email" class="form-control" placeholder="Your Email *" id="email" required data-validation-required-message="Please enter your email address.">
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<input type="tel" class="form-control" placeholder="Your Phone *" id="phone" required data-validation-required-message="Please enter your phone number.">
<p class="help-block text-danger"></p>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<textarea class="form-control" placeholder="Your Message *" id="message" required data-validation-required-message="Please enter a message."></textarea>
<p class="help-block text-danger"></p>
</div>
</div>
<div class="clearfix"></div>
<div class="col-lg-12 text-center">
<div id="success"></div>
<button type="submit" class="btn btn-xl submit_message">Send Message</button>
</div>
</div>
</form>
</div>
</div>
</div>
PHP:
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['phone']) ||
empty($_POST['message']) ||
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
echo "No arguments Provided!";
return false;
}
$name = $_POST['name'];
$email_address = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$to = 'mail.ornithas.gr';
$email_subject = "Website Contact Form: $name";
$email_body = "You have received a new message from your website contact form.\n\n"."Here are the details:\n\nName: $name\n\nEmail: $email_address\n\nPhone: $phone\n\nMessage:\n$message";
$headers = "From:mail.ornithas.gr\n";
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
return true;

check your $to email address... it looks incorrect. So mail sending fail.

Header should be separated by '\r\n' not '\n' so header variable should be
$headers = "From: masudcsep#gmail.com\r\n";
$headers .= "Reply-To:
$email_address";

Check if the URL that you entered is correct:
<form class="bg_field" name="sentMessage" action="./mail/validateform.php" method="post" id="contactForm" novalidate>
this: ./mail/validateform.php means that you have a folder mail in your current directory which further has a file called: validateform.php .
check the filename
check the code in the file.

Related

PHP form won't pass value to email anyone?

For some odd reason, the business input value won't submit to the email... it's always blank.. can someone tell me what's wrong? Thank you!
<?php
// Check for empty fields
if(isset(empty($_POST['submit']) ||
empty($_POST['email']) ||
empty($_POST['phone']) ||
empty($_POST['business']) ||
empty($_POST['message']) ||
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
echo "No arguments Provided!";
return false;
}
$name = strip_tags(htmlspecialchars($_POST['name']));
$email_address = strip_tags(htmlspecialchars($_POST['email']));
$phone = strip_tags(htmlspecialchars($_POST['phone']));
$business = strip_tags(htmlspecialchars($_POST['business']));
$message = strip_tags(htmlspecialchars($_POST['message']));
// Create the email and send the message
$to = 'somekoreanguy#gmail.com'; // Add your email address inbetween the '' replacing yourname#yourdomain.com - This is where the form will send a message to.
$email_subject = "Website Contact Form: $name";
$email_body = "You have received a new message from your website contact form.\n\n"."Here are the details:\n\nName: $name\n\nEmail: $email_address\n\nPhone: $phone\n\nBusiness: $business\n\nMessage:\n$message";
$headers = "From: noreply#yourdomain.com\n"; // This is the email address the generated message will be from. We recommend using something like noreply#yourdomain.com.
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
return true;
?>
And here's my HTML:
<form name="sentMessage" id="contactForm" novalidate method="post">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<input type="text" class="form-control" placeholder="Your Name *" id="name" required data-validation-required-message="Please enter your name.">
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<input type="email" class="form-control" placeholder="Your Email *" id="email" required data-validation-required-message="Please enter your email address.">
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<input type="tel" class="form-control" placeholder="Your Phone *" id="phone" required data-validation-required-message="Please enter your phone number.">
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<input type="text" class="form-control" placeholder="Your Business Name *" id="business" required data-validation-required-message="Please enter your business name.">
<p class="help-block text-danger"></p>
</div>
<div class="col-md-6">
<div class="form-group">
<textarea class="form-control" placeholder="Your Message *" id="message" required data-validation-required-message="Please enter a message."></textarea>
<p class="help-block text-danger"></p>
</div>
</div>
<div class="clearfix"></div>
<div class="col-lg-12 text-center">
<div id="success"></div>
<button type="submit" name="submit" class="btn btn-xl">Send Message</button>
</div>
</div>
</form>
For some reason, when I put that "empty($_POST['business']) ||" in there, nothing comes in to the email. When I remove "type="text" from my business html section the email goes through but nothing as a value. it'll just say Business: and blank....
you did not define method="post"
<form name="sentMessage" id="contactForm" novalidate>
so it will be like
<form name="sentMessage" id="contactForm" novalidate method="post">
give name for
<button type="submit" name ="submit" class="btn btn-xl">Send Message</button>
So your code will be
if(isset($_POST['submit']){
//set your code here
}
It's always blank, because no name="" in your input form, name="" to reference form data after a form is submitted. Add name="" to your input like this..
<?php
// Check for empty fields
if(isset($_POST['submit'])) {
if(trim($_POST['email'])== '' || trim($_POST['phone'])== '' || trim($_POST['business'])== '' || trim($_POST['message'])== '' || !filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
echo "No arguments Provided!";
}else{
$name = strip_tags(htmlspecialchars($_POST['name']));
$email_address = strip_tags(htmlspecialchars($_POST['email']));
$phone = strip_tags(htmlspecialchars($_POST['phone']));
$business = strip_tags(htmlspecialchars($_POST['business']));
$message = strip_tags(htmlspecialchars($_POST['message']));
// Create the email and send the message
$to = 'somekoreanguy#gmail.com'; // Add your email address inbetween the '' replacing yourname#yourdomain.com - This is where the form will send a message to.
$email_subject = "Website Contact Form: $name";
$email_body = "You have received a new message from your website contact form.\n\n"."Here are the details:\n\nName: $name\n\nEmail: $email_address\n\nPhone: $phone\n\nBusiness: $business\n\nMessage:\n$message";
$headers = "From: noreply#yourdomain.com\n"; // This is the email address the generated message will be from. We recommend using something like noreply#yourdomain.com.
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
}
}
?>
<html>
<head>
</head>
<body>
<form name="contactForm" novalidate method="POST">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<input type="text" class="form-control" placeholder="Your Name *" name="name" id="name" data-validation-required-message="Please enter your name." required>
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<input type="email" class="form-control" placeholder="Your Email *" name="email" id="email" data-validation-required-message="Please enter your email address." required>
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<input type="tel" class="form-control" placeholder="Your Phone *" name="phone" id="phone" data-validation-required-message="Please enter your phone number." required>
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<input type="text" class="form-control" placeholder="Your Business Name *" name="business" id="business" data-validation-required-message="Please enter your business name." required>
<p class="help-block text-danger"></p>
</div>
<div class="col-md-6">
<div class="form-group">
<textarea class="form-control" placeholder="Your Message *" name="message" id="message" data-validation-required-message="Please enter a message." required></textarea>
<p class="help-block text-danger"></p>
</div>
</div>
<div class="clearfix"></div>
<div class="col-lg-12 text-center">
<div name="success"></div>
<button type="submit" name ="submit" class="btn btn-xl">Send Message</button>
</form>
</body>
</html>

PHP Contact form no longer working after changing DNS [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 7 years ago.
I had my website hosting its own DNS records and mail accounts through channel. However, I migrated the email hosting over to fastmail and now have the DNS hosted through them and have A records pointing to my web hosting server IP.
Since changing to this setup, my contact form on my homepage is broken. I will attach the php code.
<?php
// Check for empty fields
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['phone']) ||
empty($_POST['message']) ||
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
echo "No arguments Provided!";
return false;
}
$name = $_POST['name'];
$email_address = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
// Create the email and send the message
$to = 'i did put my real email here.'; // Add your email address inbetween the '' replacing yourname#yourdomain.com - This is where the form will send a message to.
$email_subject = "Website Contact Form: $name";
$email_body = "You have received a new message from your website contact form.\n\n"."Here are the details:\n\nName: $name\n\nEmail: $email_address\n\nPhone: $phone\n\nMessage:\n$message";
$headers = "From: noreply#yourdomain.com\n"; // This is the email address the generated message will be from. We recommend using something like noreply#yourdomain.com.
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
return true;
?>
The HTML code:
<form name="sentMessage" id="contactForm" novalidate>
<div class="row control-group">
<div class="form-group col-xs-12 floating-label-form-group controls">
<label>Name</label>
<input type="text" class="form-control" placeholder="Name" id="name" required data-validation-required-message="Please enter your name.">
<p class="help-block text-danger"></p>
</div>
</div>
<div class="row control-group">
<div class="form-group col-xs-12 floating-label-form-group controls">
<label>Email Address</label>
<input type="email" class="form-control" placeholder="Email Address" id="email" required data-validation-required-message="Please enter your email address.">
<p class="help-block text-danger"></p>
</div>
</div>
<div class="row control-group">
<div class="form-group col-xs-12 floating-label-form-group controls">
<label>Phone Number</label>
<input type="tel" class="form-control" placeholder="Phone Number" id="phone" required data-validation-required-message="Please enter your phone number.">
<p class="help-block text-danger"></p>
</div>
</div>
<div class="row control-group">
<div class="form-group col-xs-12 floating-label-form-group controls">
<label>Message</label>
<textarea rows="5" class="form-control" placeholder="Message" id="message" required data-validation-required-message="Please enter a message."></textarea>
<p class="help-block text-danger"></p>
</div>
</div>
<br>
<div id="success"></div>
<div class="row">
<div class="form-group col-xs-12">
<button type="submit" class="btn btn-success btn-lg">Send</button>
</div>
</div>
</form>
I'm thinking it must not be sending mail properly now or something from the web host side. Any help is appreciated.
EDIT: My web host suggested using SMTP but I don't know what they mean.
It looks like mail is not enabled. If they want you to use SMTP, they probably don't allow their webservers to send email.
You could use PHPMailer to use another smtp-server, see this link.
Change the smtp-server to the one you can use (ask your provider).

How to update server side reCaptcha PHP

I am fairly new to bootstrap and this is the first I have used reCaptcha. I also don't have a lot of experience with PHP. I have designed numerous web sites and am very familiar with html(5) and css(3).
I can easily add the reCaptcha widget to my form and it displays correctly. However, I have no clue how to update my PHP file for the server side processing. Below is the code for my bootstrap contact form section and the code for my PHP file.
HTML (contact section):
<!-- Contact Section -->
<section id="contact">
<div class="container">
<div class="row">
<div class="col-lg-12 text-center">
<h2>Contact Me</h2>
<hr class="star-primary">
</div>
</div>
<div class="row">
<div class="col-lg-8 col-lg-offset-2">
<form name="sentMessage" id="contactForm" novalidate>
<div class="row control-group">
<div class="form-group col-xs-12 floating-label-form-group controls">
<label>Name</label>
<input type="text" class="form-control" placeholder="Name" id="name" required data-validation-required-message="Please enter your name.">
<p class="help-block text-danger"></p>
</div>
</div>
<div class="row control-group">
<div class="form-group col-xs-12 floating-label-form-group controls">
<label>Email Address</label>
<input type="email" class="form-control" placeholder="Email Address" id="email" required data-validation-required-message="Please enter your email address.">
<p class="help-block text-danger"></p>
</div>
</div>
<div class="row control-group">
<div class="form-group col-xs-12 floating-label-form-group controls">
<label>Phone Number</label>
<input type="tel" class="form-control" placeholder="Phone Number" id="phone" required data-validation-required-message="Please enter your phone number.">
<p class="help-block text-danger"></p>
</div>
</div>
<div class="row control-group">
<div class="form-group col-xs-12 floating-label-form-group controls">
<label>Message</label>
<textarea rows="5" class="form-control" placeholder="Message" id="message" required data-validation-required-message="Please enter a message."></textarea>
<p class="help-block text-danger"></p>
</div>
</div>
<br>
<div class="g-recaptcha" data-sitekey="mySitekey"></div>
<br>
<div id="success"></div>
<div class="row">
<div class="form-group col-xs-12">
<button type="submit" class="btn btn-success btn-lg">Send</button>
</div>
</div>
</form>
</div>
</div>
</div>
</section>
PHP (where do I put the required server-side php code here?):
<?php
// Check for empty fields
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['phone']) ||
empty($_POST['message']) ||
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
echo "No arguments Provided!";
return false;
}
$name = $_POST['name'];
$email_address = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
// Create the email and send the message
$to = 'myEmail'; // This is where the form will send a message to.
$email_subject = "Portfolio Website Message: $name";
$email_body = "You have received a new message from your portfolio website contact form.\n\n"."Here are the details:\n\nName: $name\n\nEmail: $email_address\n\nPhone: $phone\n\nMessage:\n$message";
$headers = "From: noreply#mydomain.com\n"; // This is the email address the generated message will be from.
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
return true;
?>
Thanks for your help!

PHP Mailer script not receiving POST variables

when a contact me script is run on my website, the script doesn't seem to be grabbing the POST variables from the HTML. The HTML is as follows:
<section id="contact">
<div class="container">
<div class="row">
<div class="col-lg-12 text-center">
<h2 class="section-heading">Contact Us</h2>
<h3 class="section-subheading text-muted">Fill out a form below to make an appointment, and our top masseur will be with you as soon as possible!</h3>
</div>
</div>
<!-- To Do: Change pictures, add FA's, finish "about",and remove portfolio-->
<div class="row">
<div class="col-lg-12">
<form name="sentMessage" id="contactForm" formaction="mail/contact_me.php" method="POST" novalidate>
<div class="row">
<div id="center><div class="col-md-6">
<center><div class="form-group">
<input type="text" class="form-control" placeholder="Your Name *" id="name" name="name" required data-validation-required-message="Please enter your name.">
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<input type="email" class="form-control" placeholder="Your Email *" id="email" required data-validation-required-message="Please enter your email address.">
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<input type="tel" class="form-control" placeholder="Your Phone *" id="phone" required data-validation-required-message="Please enter your phone number.">
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<input type="tel" class="form-control" placeholder="Massage Type *" id="type" required data-validation-required-message="Please enter your type of massage.">
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<input type="tel" class="form-control" placeholder="Date of desired appointment *" id="message" required data-validation-required-message="Please enter the date">
<p class="help-block text-danger"></p>
</div>
</div>
<!--<div class="col-md-6">
<div class="form-group">
<textarea class="form-control" placeholder="Please include date, and type of massage *" id="message" required data-validation-required-message="Please enter a message."></textarea>
<p class="help-block text-danger"></p>
</div>
</div> -->
<div class="clearfix"></div>
<div class="col-lg-12 text-center">
<button type="submit" class="btn btn-xl" formaction="mail/contact_me.php">Set Appointment!</button>
</div>
</div>
</form>
</div>
</div>
</div>
</section>
The PHP Script (contact_me.php) is:
<?php
if(isset($_POST['submit'])){
$to = "*****"; // this is your Email address
$from = $_POST['email']; // this is the sender's Email address
$first_name = $_POST['name'];
$subject = "New Appointment!";
$subject2 = "Copy of your Appointment credentials.";
$message = $first_name . "'s Appointment. Phone: " . $phone . " Email: " . $_POST['email'] . " Type of Massage:" . "\n\n" . $_POST['type'] . " On:" . $_POST['message'];
$message2 = "Here is a copy of your message " . $first_name . "\n\n" . $_POST['message'];
$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers);
mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
echo "Mail Sent. Thank you " . $first_name . ", we will contact you shortly.";
// You can also use header('Location: thank_you.php'); to redirect to another page.
}
?>
I tried removing the isset (Or rather changing it to !isset), and the email sent. However, the credentials and the fields that were provided at the website were completely missing, and only the given text in the script was sent.
The attribute formaction is not valid. Use action instead.
In your case:
<form name="sentMessage" id="contactForm" action="mail/contact_me.php" method="POST" novalidate>
You're also missing a name attribute, as #anant kumar singh stated.

HTML not passing content to PHP contact form

<section id="contact">
<div class="container">
<div class="row">
<div class="col-lg-12 text-center">
<h2>Contact Me</h2>
<hr class="star-primary">
</div>
</div>
<div class="row">
<div class="col-lg-8 col-lg-offset-2">
<!-- To configure the contact form email address, go to mail/contact_me.php and update the email address in the PHP file on line 19. -->
<!-- The form should work on most web servers, but if the form is not working you may need to configure your web server differently. -->
<form name="sentMessage" id="contactForm" onsubmit="return validate()" action="contactme.php">
<div class="row control-group">
<div class="form-group col-xs-12 floating-label-form-group controls">
<label>Name</label>
<input type="text" class="form-control" placeholder="Name" id="name" required data-validation-required-message="Please enter your name.">
<p class="help-block text-danger"></p>
</div>
</div>
<div class="row control-group">
<div class="form-group col-xs-12 floating-label-form-group controls">
<label>Email Address</label>
<input type="email" class="form-control" placeholder="Email Address" id="emailz" required data-validation-required-message="Please enter your email address.">
<p class="help-block text-danger"></p>
</div>
</div>
<div class="row control-group">
<div class="form-group col-xs-12 floating-label-form-group controls">
<label>Phone Number</label>
<input type="tel" class="form-control" placeholder="Phone Number" id="phone" required data-validation-required-message="Please enter your phone number.">
<p class="help-block text-danger"></p>
</div>
</div>
<div class="row control-group">
<div class="form-group col-xs-12 floating-label-form-group controls">
<label>Message</label>
<textarea rows="5" class="form-control" placeholder="Message" id="message" required data-validation-required-message="Please enter a message."></textarea>
<p class="help-block text-danger"></p>
</div>
</div>
<br>
<div id="success"></div>
<div class="row">
<div class="form-group col-xs-12">
<input type="submit" value="Submit" name="Submit" class="btn btn-success btn-lg"></input>
</div>
</div>
</form>
</div>
</div>
</div>
</section>
<-----PHP----->
<?php
if(empty($_POST['name']) ||
empty($_POST['emailz']) ||
empty($_POST['phone']) ||
empty($_POST['message']) ||
!filter_var($_POST['emailz'],FILTER_VALIDATE_EMAIL))
{
echo "No arguments Provided!!";
return false;
}
$name = $_POST['name'];
$email = $_POST['emailz'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$headers = "From: noreply#yourdomain.com\n"; // This is the email address the generated message will be from
$headers .= "Reply-To: $emailz";
$subject = 'New Message - Kieronb- $name';
$body = "You have received a new message from your website contact form.\n\n"."Here are the details:\n\nName: $name\n\nEmail: $emailz\n\nPhone: $phone\n\nMessage:\n$message";
mail("k#gmail.com",$subject,$body,$headers);
return true;
?>
SO, the above is the HTML and the PHP, now the majority of this code has been frankensteined from a bootstrap project, but i thought i would just have a play with the contact form too, but it is going all the way through to the missing arguments catch at the beginning of the PHP.
I cant see why the data is coming through empty- have i missed something painfully obvious?
I am running on a web server, not locally.
Thanks
Edit; thanks everyone, i forgot my method, and names on the form!
Your form fields do not have the name attribute. Without them their values are not submitted with the form.
<input type="email" class="form-control" placeholder="Email Address" id="emailz" required data-validation-required-message="Please enter your email address.">
should be
<input type="email" name="emailz" class="form-control" placeholder="Email Address" id="emailz" required data-validation-required-message="Please enter your email address.">
And your <form> needs to have the method specified as POST or else it defaults to GET:
<form method="post" name="sentMessage" id="contactForm" onsubmit="return validate()" action="contactme.php">

Categories