Contact form in php doesnt receive mail for hotmail - php

I m trying contact form in php.I receive the mails in gmail,yahoo etc but doesnt recieve any mails in hotmail.I tried a lot but doesnt know whats the problem.Why i cant recieve mail in hotmail? Here is the code.
if (empty($error)) {
$to = 'abc#gmail.com, ' . $email;
$subject = " contact form message";
$repEmail = 'abc#gmail.com';
$headers = 'From: Contact Detail <'.$repEmail.'>'.$eol;
$content = "Contact Details: \n
Name:$name \n
Batch: $batch \n
Email: $email \n
mobile: $mobile " ;
$success = "<b>Thank you! Your message has been sent!</b>";
mail($to,$subject,$content,$headers);
}
}
?>

Check the server admin's email for bounce messages. I would guess it has to do with hotmail rejecting it either because it doesn't like your host or because you don't have SPF or DKIM signing set up. Either way, the blame is probably on your server email administrator more than on your code. Email is actually kinda complex to set up nowadays given all the anti-spam stuff you have to do.
You might want to consider using a third party email service. SMTP through a gmail account or Amazon SES so they'll take care of more of these details. This can be set up by the server admin too, or done in PHP with libraries. Is there a SMTP mail transfer library in PHP

this is more likely
if (isset($_REQUEST['email']))
//if "email" is filled out, send email
{
//send email
$email = $_REQUEST['email'] ;
$subject = 'Order' ;
$message =
'Product Name :'. $_REQUEST['proname']."\n". //these all are example details
'Name :'.$_REQUEST['name']."\n".
'Phone :'. $_REQUEST['phone']."\n".
'City :'.$_REQUEST['city']."\n".
'Address :'.$_REQUEST['address']."\n".
'Quantity :'. $_REQUEST['select'];
if ($email == "" || $subject == "" || $message == "" )
{
echo 'Please fill the empty fields';
}
else{
mail("anything#something.com", $subject,
$message, "From:" . $email);
echo 'Thank you ! we will contact you soon';
}
}

Related

Fasthosts shared platform PHP mail from web page issue -F

I am trying to send email from a web page hosted on a shared platform over at fasthosts. I cannot for the life of me get this to work, I had a much more extensive script which checked the validity of email etc, but now I've been reduced to using the basic example from fasthosts and it is still not working.
Please could someone take a look and let me now where I am going wrong...
<?php
// You only need to modify the following two lines of code to customise your form to mail script.
$email_to = "contact#mywebsite.co.uk"; // Specify the email address you want to send the mail to.
$email_subject = "Feedback from website"; // Set the subject of your email.
// This is the important ini_set command which sets the sendmail_from address, without this the email won't send.
ini_set("contact#mywebsite", $email_from);
// Get the details the user entered into the form
$name = $_POST["name"];
$email = $_POST["email"];
$message = $_POST["message"];
// Validate the email address entered by the user
if(!filter_var($email_from, FILTER_VALIDATE_EMAIL)) {
// Invalid email address
die("The email address entered is invalid.");
}
// The code below creates the email headers, so the email appears to be from the email address filled out in the previous form.
// NOTE: The \r\n is the code to use a new line.
$headers = "From: " . $email_from . "\r\n";
$headers .= "Reply-To: " . $email_from . "\r\n"; // (You can change the reply email address here if you want to.)
// Now we can construct the email body which will contain the name and message entered by the user
$message = "Name: ". $name . "\r\nEmail: " . $email . "\r\nMessage: " . $message ;
// Now we can send the mail we've constructed using the mail() function.
// NOTE: You must use the "-f" parameter on Fasthosts' system, without this the email won't send.
$sent = mail($email_to, $email_subject, $message, $headers, "-f" . $email_from);
// If the mail() function above successfully sent the mail, $sent will be true.
if($sent) {
$output = json_encode(array('type'=>'message', 'text' => 'Hi '.$name .' Thank you for contacting us.'));
die($output);
} else {
$output = json_encode(array('type'=>'error', 'text' => 'Could not send mail! Please check your PHP mail configuration.'));
die($output);
}
?>

My contact us PHP Form is sending 7 emails per submission

Well my PHP contact us form is sending email too well
But I am getting 7 emails per submission
Problem is I have no idea why I am getting 7 emails per submission.
Any thoughts?
CODE
<?php
if(isset($_POST['Send'])){
$first_name =trim($_POST['first_name']);
$last_name=trim($_POST['last_name']);
$phone_number=trim($_POST['phone_number']);
$email=trim($_POST['email']);
$msg=trim($_POST['msg']);
$name=$first_name." ".$last_name;
if($first_name == '' ||$last_name =='' || $phone_number == '' || $email == ''|| $msg == '' ){
$merror = "<p style='color:red;'> * Kindly fill all Fileds<p>";
}else{
foreach($_POST as $value){
if(stripos($value, 'Content-Type:')!== FALSE || $_POST['Address']!== "" ) {
$merror = "<p style='color:red;'> * The information you have entered has a problem</p>";
}else{
require_once "class.phpmailer.php";
$mail= new PHPMailer();
if(!$mail->ValidateAddress($email)){
$merror = "<p style='color:red;'> * Please enter a valid email address</p>";
}else{
$email_body = "";
$email_body = $email_body . "Name: ". $name ."<br>";
$email_body = $email_body . "Phone: ". $phone_number. "<br>";
$email_body = $email_body . "Email: ". $email . "<br>";
$email_body = $email_body . "Message: " . $msg . "<br>";
$mail->SetFrom($email, $name);
$address = "s#example.co";
$mail->AddAddress($address, Trial);
$mail->Subject= "Ess contact form message ".$name;
//$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($email_body);
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
echo"<script>window.open('Contact.php','_self')</script>";
}
echo"<script>window.open('Contact.php?status=thanks','_self')</script>";
}
}
}
}
}
?>
You also have a very common error a lot of people have with "Contact Us" forms.
$mail->SetFrom($email, $name);
This will break SPF and also cause DMARC to fail and you will never get the message from some people, if your mail server you use has DMARC enabled on it and GMAIL does.
Since DMARC is a more recent protocol, a lot of the old cookie cutter code for contact us forms - doesn't take this into account.
You can read more about that here: "DMARC - Contact Us Form Nightmare"
The suggested workaround will be to do:
$mail->SetFrom("<Your email Adddress>, $name);
You have the the customers contact email in the body of the message which is perfect.
This way - you avoid the issue outline in the article. You won't quickly be able to hit the "Reply" button, but at least you'll get the emails from those customers who have DMARC enabled.

PHP mail form is being sent to Gmail spam [duplicate]

This question already has answers here:
How do you make sure email you send programmatically is not automatically marked as spam?
(24 answers)
Closed 7 years ago.
Can someone help me figure out why the below PHP is causing the email to be sent to Gmail spam? I tried following other directions for setting proper headers, but I still run into problems with my emails going into the spam filter in Gmail.
Any help would be appreciated!
<?php
//set validation error flag as false
$error = false;
//check if form is submitted
if (isset($_POST['submit']))
{
$name = trim($_POST['txt_name']);
$fromemail = trim($_POST['txt_email']);
$inquiry = trim($_POST['txt_inquiry']);
$message = trim($_POST['txt_msg']);
//name can contain only alpha characters and space
if (!preg_match("/^[a-zA-Z ]+$/",$name))
{
$error = true;
$name_error = "Please enter a real name";
}
if(!filter_var($fromemail,FILTER_VALIDATE_EMAIL))
{
$error = true;
$fromemail_error = "Please enter a valid email address";
}
if(empty($inquiry))
{
$error = true;
$inquiry_error = "Please enter your subject";
}
if(empty($message))
{
$error = true;
$message_error = "Please enter your message";
}
if (!$error)
{
//send mail
$toemail = "myemail#gmail.com";
$subject = "inquiry from visitor " . $name;
$body = "Here goes your Message Details: \n\n Name: $name \n From: $fromemail \n Inquiry: $inquiry \n Message: \n $message";
$headers = "From: $fromemail\n";
$headers .= "Reply-To: $fromemail";
$headers .= "Return-Path: $fromemail";
if (mail ($toemail, $inquiry, $body, $headers))
$alertmsg = '<div class="alert alert-success text-center">Message sent successfully. We will get back to you shortly!</div>';
else
$alertmsg = '<div class="alert alert-danger text-center">There is error in sending mail. Please try again later.</div>';
}
}
?>
It could be that your ip address of the server that you are sending the email with it used for other purposes that marked it as a spam address.
Most of the time when you add DKIM and SPF to your email server (if you use one) will solve this problem.
An essier solution would be to use an external mailing service so that you they can handle that for you
I often made the experience, that mails that are directly getting sent by PHP are recognized as SPAM...
my approach is now, to always use a SMTP-Server for sending those emails...
this post could help you!

PHP Mail script problems

This is the first time I've used PHP at all and I'm having trouble implementing a mail form of all things, I can't seem to get this working. Below is my code, I'd be most appreciative if somebody could point me in the right direction in terms of debugging.
<?php
$job_number = $_POST['job_number'];
$completion_time = $_POST['completion_time'];
$email = $_POST['email'];
$formcontent = "From: $email \n \n Job Number: $job_number \n \n Completion Time: $completion_time \n";
$recipient = "data#rak.co.uk";
$subject = "Repeat Order";
$mailheader = "From: $email \r\n";
mail(
$recipient,
$subject,
$formcontent,
$mailheader
)
or die(
"
Error!
"
);
echo( "
<div style='font-size:24px; margin-top: 100px; text-align: center;'>
Thank You!
"
. " - " .
" <a href='home.html' style='color: #1ca03e;'>
Return Home
</a>
</div>
"
);
?>
Thank you,
Cameron
edit: Some more info, the server supports PHP mail scripts as it had one on there before (according to the friend I'm building this for), the error I've had while internal testing is that the mail is being sent but without any of the '$formcontent' content... Only the titles (aka: From:, Job Number:, Completion Time:)
edit edit: if it helps here is a staging server I have it up on at the moment (don't hate me for poor web-design... it's a work in progress) http://temp.fullaf.com/cameron/rak/repeat.html
You can get the swiftmailer package on their site here -> http://swiftmailer.org/
require_once 'swiftmailer/lib/swift_required.php';
function new_mail($subject, $content, $recipients, $from)
{
// Create the message
$message = Swift_Message::newInstance();
// Give the message a subject
$message->setSubject($subject);
// Set the From address with an associative array
$message->setFrom($from);
// Set the To addresses with an associative array
$message->setTo($recipients);
// Give it a body
$message->setBody($content);
$transport = Swift_MailTransport::newInstance();
$mailer = Swift_Mailer::newInstance($transport);
$result = $mailer->send($message);
}
$job_number = $_POST['job_number'];
$completion_time = $_POST['completion_time'];
$email = $_POST['email'];
$message = "From: $email \n \n Job Number: $job_number \n \n Completion Time: $completion_time \n";
$recipients = array('data#rak.co.uk' => 'Your name of choice');
$subject = "Repeat Order";
$from = array($email => 'Name of choice.');
new_mail($subject, $message, $recipients, $from);
I'm currently not in the position where I can access a ftp server to test this specific snippet but try it out. If there are any problems let me know.
Your code is working and sending email without any issues.
Check your email mail Spam box. Some times, the email will go to Spam box.
You are using this "data#rak.co.uk" email address as recipient email. So don't use the same email address for sender email address. Use another email address as sender email.
Make sure, Your email address "data#rak.co.uk" is receiving emails properly, when send email from other email accounts such as yahoo and gmail.
Please make sure, you have setup the mail server properly in your server.

Some contact form emails not being sent due to spam filtering on host

I need my contact form on my website to be adjusted. It's a PHP/Ajax Contact Form.
Currently i have a problem - When a client fills out my contact form NAME - EMAIL - SUBJECT - MESSAGE there is an issue with my DREAMHOST Server due to their new anti spam policy and i dont receive some messages - If their email is #hotmail.com that's fine. But if their email is #gmail.com i dont get the message etc.
DREAMHOST TELLS ME:
Thanks for contacting Tech Support I checked the logs for the form on your site and did see that the emails are being bounced by the server due to recently implemented anti spam policies which won't allow email sent from the server using non-Dreamhost outgoing servers or "send from" email addresses. You can read more details on this policy here:
http://wiki.dreamhost.com/Sender_Domain_Policy_and_Spoofing
Your mail form uses the visitor's email address as the 'From' address which in most cases is not a Dreamhost hosted email address. Due to the spam policy above, the server will block mail being sent off the server if the email addresses are not using Dreamhost mail servers. So what you will need to do is either set the mail form to use your Dreamhost hosted address as the 'From' address.
Or you will need to find another mail form that will allow you to set a fixed email address as the 'From' address. This way you can set a Dreamhost hosted email address in the form as the 'From' address.
THE CODE AS FOLLOWS:
<?php
/*
Credits: Bit Repository
URL: http://www.bitrepository.com/
*/
include dirname(dirname(__FILE__)).'/config.php';
error_reporting (E_ALL ^ E_NOTICE);
$post = (!empty($_POST)) ? true : false;
if($post)
{
include 'functions.php';
$name = stripslashes($_POST['name']);
$email = trim($_POST['email']);
$subject = stripslashes($_POST['subject']);
$message = stripslashes($_POST['message']);
$error = '';
// Check name
if(!$name)
{
$error .= 'Please enter your name.<br />';
}
// Check email
if(!$email)
{
$error .= 'Please enter an e-mail address.<br />';
}
if($email && !ValidateEmail($email))
{
$error .= 'Please enter a valid e-mail address.<br />';
}
// Check message (length)
if(!$message || strlen($message) < 15)
{
$error .= "Please enter your message. It should have at least 15 characters.<br />";
}
if(!$error)
{
$mail = mail(WEBMASTER_EMAIL, $subject, $message,
"From: ".$name." <".$email.">\r\n"
."Reply-To: ".$email."\r\n"
."X-Mailer: PHP/" . phpversion());
if($mail)
{
echo 'OK';
}
}
else
{
echo '<div class="notification_error">'.$error.'</div>';
}
}
?>
All i need to know is what i need to do to the code so i can receive all submissions of my contact form. I would really be grateful if someone could help.
Replace the following:
mail = mail(WEBMASTER_EMAIL, $subject, $message,
"From: ".$name." <".$email.">\r\n"
."Reply-To: ".$email."\r\n"
with just:
$mail = mail(WEBMASTER_EMAIL, $subject, $message,"X-Mailer: PHP/" . phpversion());
and add the user's email address to your message if you need to. What you are doing right now is called spoofing and even when well-intentioned, you are essentially committing fraud. It would be the equivalent of someone calling you to show interest in your product and you taking down their physical address and putting that in the upper-left corner of an envelope and then sending yourself a letter saying that the caller is interested. In addition to this just being a fairly-odd way of doing things, it also suggests an electronic paper trail that suggests the user actually emailed you, which they did not. I personally would be uncomfortable finding out my email address was used in this way after filling out an online form.

Categories