This question already has answers here:
How do you make sure email you send programmatically is not automatically marked as spam?
(24 answers)
Online SpamAssassin evaluation / RFC conformant check [closed]
(1 answer)
Closed 4 years ago.
I'm using the mail() to send a simple email but from some reason everything I try it goes straight to spam, am I missing something here?
<?php
$to = "toemail#example.com";
$subject = "your subject";
$body = "<p>Your Body</p>";
$headers = "From: Sender Name <from#example.com>" . "\r\n";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
mail($to, $subject, $body, $headers);
?>
You need an additional 'Reply-to' Header to ensure that the sender e-mail address is the same as the reply-to mail address. This should solve your problem.
e.g $headers = "From: $from\r\nReply-to: $email";
Also make sure that your headers are seperated by \r\n
Related
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 3 years ago.
I'm sending email using php header.
$to = 'test#email.com';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$message = '<h1>Test</h1>';
mail($to, $subject, $message, $headers);
This function is working properly.
But after I added "From" mail() function is not working.
$headers .= "From: from#address.com";
Any idea?
May you are trying to spoof email, so it's getting failed.
It would be great practise to keep using Reply-To with From while using mail()
$headers .= "From: from#address.com\r\n";
$headers .= "Reply-To: from#address.com\r\n";
But, personally suggest you to use SMTP instead of mail() or PHPMailer.
This question already has answers here:
Setting up a Ubuntu/Apache/PHP machine to send email
(5 answers)
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 5 years ago.
Hi,
I am running a Centos 7 but I cant send php mail. I dont get any error whatsoever. The mail simply wont reach its destination.
This is my script:
<?php
date_default_timezone_set('America/Los_Angeles');
mb_internal_encoding('UTF-8');
if(isset($_POST['submit'])){
$name=$_POST['name'];
$email=$_POST['email'];
$subject=$_POST['subject'];
$to = $_POST['target'];
$message = $_POST['message'];
$from_name = mb_encode_mimeheader($name,'UTF-8');
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=utf-8\r\n";
$headers .= "To: $name <$to>\r\n";
$headers .= "From: $from_name <$email>\r\n";
mail($to, $subject, $message, $headers);
}
?>
how can I configure this so it will at least let me know why is not sending the mail?
Thank you.
This question already has answers here:
How do I prevent mails sent through PHP mail() from going to spam? [duplicate]
(6 answers)
Closed 5 years ago.
I have done everything possible but after registration my email goes to spam and i want it to go into inbox
$subject = 'Confirm your email';
$to = $email;
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: CGOTY <info#cgoty.com>' . "\r\n";
$body='Hi, Click here to confirm your email https://cgoty.com/activate.php?encrypt='.$encrypt.'&action=activate ';
mail($to,$subject,$message,$headers);
You made a mistake in your script within you mail contructor of function you said message instead of body message instead of body.
So it should look like this
$body='Hi, Click here to confirm your email https://cgoty.com/activate.php?encrypt='.$encrypt.'&action=activate ';
mail($to,$subject,$body,$headers);
It will work for you
Add this to your header:
$headers .= "Reply-To: $email" . "\r\n";
(replace $email with the mail you want)
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 6 years ago.
My mails using php mail() are going to the junk mail folder - why?
<?php
ob_start();
session_start();
//define the receiver of the email
$from='mrashidap#gmail.com';
$to = 'mrashidap#gmail.com';
//define the subject of the email
$subject = 'inform me please, when u receive this mail';
//create a boundary string. It must be unique
//so we use the MD5 algorithm to generate a random hash
$random_hash = md5(date('r', time()));
//define the headers we want passed. Note that they are separated with \r\n
#Now We Can Use HTML Tags
$headers = "From: " . strip_tags($from). "\r\n";
$headers .= "Organization: appstribes\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers .= "Reply-To: ".($from) . "\r\n";
$headers .= "Return-Path: ".($from) . "\r\n";
$headers .= "X-Priority:3 \r\n";
$headers .= "X-Mailer: PHP". phpversion() ."\r\n";
$headers .= "X-MSMail-Priority: high\r\n";
$msg = '<html><body>';
$msg .= '<p>Dear Sir/Madam</p><br/>';
$msg .= '<p><strong>GOOD DAY..!!!</strong></p>';
$msg .= '<p>Thank you for contacting Keita Customer Service. We regret any inconvenience you have experienced. Your request has been received, and a ticket has been created for you with,</p>';
$msg .= '<p><strong>Reference ID : khd004</strong></p>';
$msg .= '<p>Our team is looking into your request and you can expect next to be contacted with either an answer to your question(s) or a solution to the issue(s) raised. Our expected time-frames to respond will vary according to the severity or complexity of the matter being addressed and volume of contacts reaching us. However we assure you that we are working to get back to you as fast as possible and to properly address your questions and concern.</p>';
$msg .= '<p>Regards,</p>';
$msg .= '<p>Keita IT Team</p><br/>';
$msg .= '</body></html>';
$message=$msg;
//send the email
$mail_sent = #mail( $to, $subject, $message, $headers );
//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed"
echo $mail_sent ? "Mail sent" : "Mail failed";
?>
Most of the mails are going to junk. However mail sending to gmail are getting in inbox itself.
Your script claims this email is sent from gmail, which is not true
Not clear whether your server signs emails with DKIM or not, does it have SPF or not
Server may be graylisted
Google may not designate your domain as a permitted sender
Any of these reasons may lead to considering your emails as spam.
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
PHP: How to avoid a system generated e-mail going into spam?
How to send 100.000 emails weekly?
I am using the following script to send mail
$to = 'name#test.com' . ', ';
$to .= 'name2#test.com';
$subject = 'Green apple';
$message = 'Enquiry posted by test ';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: Green Apple <info#greenappleme.com>' . "\r\n";
if (mail($to, $subject, $message, $headers))
{
echo "mail send successfully";
}
else
echo "mail can't send";
When I use this script to some servers, the mail is going to spam. But in some servers, it is going to the Inbox as desired.
How can I prevent email going to spam?
To prevent an email going into spam, don't send with mail from PHP. Send it with SMTP from your server, you can use PHP to connect to SMTP and submit the message. You will then need to set the SPF records on your server, and reverse DNS records with whoever your IP address comes from. If you do these three things then you'll be on the whitelist and all your emails will go into the inbox everywhere, assuming you don't abuse the privilege and get put on a blacklist.
So: send using SMTP, research SPF records and reverse DNS.
You won't be able to do this unless you have a dedicated server with dedicated IP for the domain from which you are sending the email from.
Be sure to set the RETURN PATH as the optional 5th parameter to the mail() function.
if (mail($to, $subject, $message, $headers, '-finfo#greenappleme.com'))
TO send ur majority mail in inbox set below headers and dont use test like keywords in your subject line
$headers = "From: My site<noreply#example.com>\r\n";
$headers .= "Reply-To: info#example.com\r\n";
$headers .= "Return-Path: info#example.com\r\n";
$headers .= "X-Mailer: Drupal\n";
$headers .= 'MIME-Version: 1.0' . "\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";