not receiving php mail() messages from remote host - php

I have a email form Here and am invoking the mail() function. for some reason I am not receiving any emails to my email account. My only guess is that it could be some config on the server
Here is my php script:
<?php
header('Content-type: application/json');
$status = array(
'type'=>'success',
'message'=>'Email sent!'
);
$name = #trim(stripslashes($_POST['name']));
$email = #trim(stripslashes($_POST['email']));
$subject = #trim(stripslashes($_POST['subject']));
$message = #trim(stripslashes($_POST['message']));
$email_from = $email;
$email_to = 'keilcarpenter01#gmail.com';
$body = 'Name: ' . $name . "\n\n" . 'Email: ' . $email . "\n\n" . 'Subject: ' . $subject . "\n\n" . 'Message: ' . $message;
$success = #mail($email_to, $subject, $body, 'From: <'.$email_from.'>');
echo json_encode($status);
die;
And the html form:
<h1>Contact Form</h1>
<p>Send me a message and I will get back to you!</p>
<div class="status alert alert-success" style="display: none"></div>
<form id="main-contact-form" class="contact-form" name="contact-form" method="post" action="sendemail.php" role="form">
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<input type="text" name="name" class="form-control" required="required" placeholder="Name">
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<input type="text" name="email" class="form-control" required="required" placeholder="Email address">
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div class="form-group">
<textarea name="message" id="message" required="required" class="form-control" rows="8" placeholder="Message"></textarea>
</div>
<div class="form-group">
<button type="submit" class="btn btn-danger btn-lg">Send Message</button>
</div>
</div>
</div>
</form>
Could it be some config on the remote host or something wrong on my end?
I read that if your sending from localhost then you need to config the php.ini and sendmail.ini so I know that is out of the question.
Would PHPMailer be better to use?

Related

send mail feature in html + php

I want to send an email with PHP when a user has finished filling in an HTML form and then emailing information from the form. I have below code but was not getting form values in mail. Can someone help me regarding this?
<form id="main-contact-form" class="contact-form" name="contact-form" method="post" action="sendemail.php" role="form">
<div class="row">
<div class="col-sm-5">
<div class="form-group">
<input type="text" class="form-control" required="required" placeholder="First Name" name="name">
</div>
<div class="form-group">
<input type="text" class="form-control" required="required" placeholder="Last Name" name="lname">
</div>
<div class="form-group">
<input type="text" class="form-control" required="required" placeholder="Email address" name="email">
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary btn-lg" name="submit">Send Message</button>
</div>
</div>
<div class="col-sm-7">
<textarea name="message" id="message" required="required" class="form-control" rows="8" placeholder="Message"></textarea>
</div>
</div>
</form>
**sendemail.php**
<?php
header('Content-type: application/json');
$status = array(
'type'=>'success',
'message'=>'Email sent!'
);
$name = #trim(stripslashes($_POST['name']));
$email = #trim(stripslashes($_POST['email']));
$subject = "Mail from your website";
$message = #trim(stripslashes($_POST['message']));
$email_from = $email;
$email_to = 'manish22it#gmail.com';
$body = 'Name: ' . $name . "\n\n" . 'Email: ' . $email . "\n\n" . 'Subject: ' . $subject . "\n\n" . 'Message: ' . $message;
$success = #mail($email_to, $subject, $body, 'From: <'.$email_from.'>');
echo json_encode($status);
die;
?>

Html and php form [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 7 years ago.
I'm trying to create a html and php contact form but it doesn't seem to be working.
I'm sure it's a simple answer but I can't figure it out.
Can anyone tell me were i'm going wrong?
It doesn't redirect to the mail.php page.
<div class="col-lg-8">
<form action="mail.php" class="form-horizontal" id="contactForm" name="contactForm" method="post" >
<div class="form-group" >
<label for="first-name" class="col-lg-2">First name</label>
<div class="col-lg-10">
<input type="text" class="form-control" id="first-name" name="first-name" placeholder="What your mam calls you ">
</div>
</div><!--end form group-->
<div class="form-group">
<label for="last-name" class="col-lg-2">Last name</label>
<div class="col-lg-10">
<input type="text" class="form-control" id="last-name" name="last-name" placeholder="What your army buddies call you">
</div>
</div><!--end form group-->
<div class="form-group">
<label for="email" class="col-lg-2">Email</label>
<div class="col-lg-10">
<input type="text" class="form-control" id="email" name="email" placeholder="Enter your email address, we won't send you junk mail">
</div>
</div><!--end form group-->
<div class="form-group">
<label for="website" class="col-lg-2">Your current website</label>
<div class="col-lg-10">
<input type="text" class="form-control" id="website" name="website" placeholder="If you have one.">
</div>
</div><!--end form group-->
<div class="form-group">
<label for="message" class="col-lg-2">Any Message</label>
<div class="col-lg-10">
<textarea name="message" id="message" name="message" class="form-control"
cols="20" rows="10" placeholder="Maybe tells us a bit about your business. I'll start, mine is web development. ;)"></textarea>
</div>
</div><!--end form group-->
<div class="form-group">
<div class="col-lg-10 col-lg-offset-2">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</form>
</div>
</div><!--end of row-->
</section>
</div>
mail.php
<html>
<body>
<?php
if(isset($_POST['submit'])){
$to = "info#wonderfulwebsites.ie"; // this is your Email address
$from = $_POST['email']; // this is the sender's Email address
$f_name = $_POST['first_name'];
$s_name = $_POST['last_name'];
$subject = "Form submission";
$subject2 = "Copy of your form submission";
$message = $f_name . " " . $s_name . " wrote the following:" . "\n\n" . $_POST['message'] "\n" $website = $_POST['website'];
$message2 = "Here is a copy of your message " . $f_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 " . $f_name . ", we will contact you shortly.";
// You can also use header('Location: thank_you.php'); to redirect to another page.
// You cannot use header and echo together. It's one or the other.
}
?>
</body>
</html>
Change this:
<button type="submit" class="btn btn-primary">Submit</button>
to this:
<input type="submit" class="btn btn-primary" value="Submit" />

Php Error with Contact Form email received without content

I have a contact form using php however when I test the form I receive an email with no content in the fields, I have checked that the fields match with the php but cannot seem to identify the problem.
The form html part of the contact page:
<section id="contact-page">
<div class="container">
<div class="center">
<h2>Send us a Message</h2>
<p class="lead">Thanks for your enquiry we will respond within 24 hours. * Indicates required information</p>
</div>
<div class="row contact-wrap">
<div class="status alert alert-success" style="display: none"></div>
<form action="sendemail2.php" method="post" id="main-contact-form" class="contact-form" name="contact-form" >
<div class="col-sm-5 col-sm-offset-1">
<div class="form-group">
<label>Name *</label>
<input type="text" name="name" class="form-control" required>
</div>
<div class="form-group">
<label>Email *</label>
<input type="email" name="email" class="form-control" required>
</div>
<div class="form-group">
<label>Phone</label>
<input type="number" name="tel"class="form-control">
</div>
<div class="form-group">
<label>Company Name</label>
<input type="text" name="company" class="form-control">
</div>
</div>
<div class="col-sm-5">
<div class="form-group">
<label>Subject *</label>
<input type="text" name="subject" class="form-control" required>
</div>
<div class="form-group">
<label>Message *</label>
<textarea name="message" id="message" required class="form-control" rows="8"></textarea>
</div>
<div class="form-group">
<button type="submit" name="submit" class="btn btn-primary btn-lg" required="required">Submit Message</button>
</div>
</div>
</form>
</div><!--/.row-->
</div><!--/.container-->
</section><!--/#contact-page-->
The Php script:
<?php
header('Content-type: application/json');
$status = array(
//'type'=>'success',
//'message'=>
'Thank you for contacting us. As early as possible we will contact you '
);
$name = #trim(stripslashes($_POST["name"]));
$email = #trim(stripslashes($_POST["email"]));
$subject = #trim(stripslashes($_POST["subject"]));
$tel = #trim(stripslashes($_POST["tel"]));
$company = #trim(stripslashes($_POST["company"]));
$message = #trim(stripslashes($_POST["message"]));
$email_from = $email;
$email_to = 'xxx#xxx.com';//replace with your email
$body = 'Name: ' . $name . "\n\n" . 'Email: ' . $email . "\n\n" . 'Subject: ' . $subject . "\n\n" . 'Phone Number: ' . $tel . "\n\n" .'Company Name : ' . $company . "\n\n" . 'Message: ' . $message;
$success = #mail($email_to, $subject, $body, 'From: <'.$email_from.'>');
echo json_encode($status);
die;
Any help would be appreciated.
Thanks
or use
<form method="post" id="main-contact-form" class="contact-form" name="contact-form" >
in place of
<form action="sendemail2.php" method="post" id="main-contact-form" class="contact-form" name="contact-form" >

PHP isn't sending mail

I am building a website using a Linode VPS.
I am using Apache and PHP installed using:
apt-get install apache2 php
This is the HTML form:
<form action="" class="form-horizontal" method="post">
<div class="form-group">
<label class="col-sm-2 control-label">Name</label>
<div class="col-sm-10">
<input type="email" class="form-control" name="name" placeholder="Name">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Email</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="email" placeholder="Email">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">IP</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="ip" value="<?php echo $_SERVER['REMOTE_ADDR']; ?>" disabled>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Message</label>
<div class="col-sm-10">
<textarea class="form-control" rows="4" name="message"></textarea>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default">Submit</button>
</div>
</div>
</form>
This is the PHP attempting to send mail:
<?php
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(-1);
if(isset($_POST['email'])) {
$email_to = "webmaster#domain.com";
$email_subject = "Contact Form";
$name = $_POST['name'];
$email = $_POST['email'];
$ip = $_POST['ip'];
$message = $_POST['message'];
$email_message = "Name: ".$name."\n";
$email_message .= "Email: ".$email."\n";
$email_message .= "IP: ".$ip."\n";
$email_message .= "Message: ".$message."\n";
$headers = 'From: '.$email."\r\n".
'Reply-To: '.$email."\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($email_to, $email_subject, $email_message, $headers);
?>
<div class="panel panel-success">
<div class="panel-body">
Message sent.
</div>
</div>
<?php
}
?>
The problem is that no e-mail is received and no e-mail is marked as spam.
I added PHP error reporting:
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(-1);
which doesn't report any errors.
First you should say which mailer is configurated on your server.
Secoundary i'd check if that mailer and the correct path is indicated in the php.ini config file.
Just a starting point...

Contact form sends email but without user inputs

This bootstrap using html/php contact form sends me an email just fine, but without any of the users input information!
The email I received looks empty like this:
Name:
Email:
Subject:
Message:
The html for the form is:
<section id="partner">
<div class="container">
<div class="center wow fadeInDown">
<h2><br>Contact</h2>
<p class="lead">Send a general enquiry here or order your service here.</p>
</div>
<div class="row contact-wrap">
<div class="status alert alert-success" style="display: none"></div>
<form id="main-contact-form" class="contact-form" name="contact-form" method="post" action="sendemail.php">
<div class="col-sm-5 col-sm-offset-1">
<div class="form-group">
<label>Name *</label>
<input type="text" name="name" class="form-control" required="required">
</div>
<div class="form-group">
<label>Email *</label>
<input type="email" name="email" class="form-control" required="required">
</div>
<div class="form-group">
<label>Phone</label>
<input type="number" class="form-control">
</div>
<div class="form-group">
<label>Company Name</label>
<input type="text" class="form-control">
</div>
</div>
<div class="col-sm-5">
<div class="form-group">
<label>Subject *</label>
<input type="text" name="subject" class="form-control" required="required">
</div>
<div class="form-group">
<label>Message *</label>
<textarea name="message" id="message" required="required" class="form-control" rows="8"></textarea>
</div>
<div class="form-group">
<button type="submit" name="submit" class="btn btn-primary btn-lg" required="required">Submit Message</button>
</div>
</div>
</form>
</div><!--/.row-->
</div><!--/.container-->
</section><!--/#contact-page-->
The PHP for the form looks like this:
<?php
header('Content-type: application/json');
$status = array(
'type'=>'success',
'message'=>'Thank you for contact us. As early as possible we will contact you '
);
$name = #trim(stripslashes($_POST['name']));
$email = #trim(stripslashes($_POST['email']));
$subject = #trim(stripslashes($_POST['subject']));
$message = #trim(stripslashes($_POST['message']));
$email_from = $email;
$email_to = 'heerschapnikki#gmail.com';//replace with your email
$body = 'Name: ' . $name . "\n\n" . 'Email: ' . $email . "\n\n" . 'Subject: ' . $subject . "\n\n" . 'Message: ' . $message;
$success = #mail($email_to, $subject, $body, 'From: <'.$email_from.'>');
echo json_encode($status);
die;
Why isn't it working properly? The message "thank you for contacting us" pops up fine and the email sends through, but non of the users information comes through.
Try to print the values you are sending. So use this:
var_dump( $_POST['name'] );
var_dump( $_POST['email'] );
etc...
Doing this, you will be able to see wether your fields are even posted correctly.
the fields have no id param. in the post you get the "id" nor the "name"
<label>Name *</label>
<input type="text" id="name" class="form-control" required="required">
</div>
<div class="form-group">
<label>Email *</label>
<input type="email" id="email" class="form-control" required="required">

Categories