Not receiving mails php mail outlook - php

I have a problem with the dynamic sending of emails from my site
Customers who have hotmail, live emails do not receive emails (which are in bcc receive emails) as well as some customers with gmail for example receive them but in spam and others in main. The code I use
function emailDemande($email, $nameL){
if (!preg_match("#^[a-z0-9._-]+#(hotmail|live|msn).[a-z]{2,4}$#", $email))
{
$passage_ligne = "\r\n";
}
else
{
$passage_ligne = "\n";
}
$subject = 'Votre demande d\'expérience mystère';
$headers = "From: site <contact#site.com>".$passage_ligne;
$headers .= "Bcc: compte#gmail.com".$passage_ligne;
$headers .= "MIME-Version: 1.0".$passage_ligne;
$headers .= "Content-Type: text/html; charset=UTF-8".$passage_ligne;
$message = '<html><body><p>Cher(e) '.$nameL.',</p></body></html>';mail($email, $subject, $message, $headers);};

I assume you are using Cpanel hosting.
What you want to do is.
Go to Cpanel > MX entry > Select Domain name in question > Select Remote Mail Exchanger.
Thats it.

Related

How to avoid PHP mail output going to junk mail? [duplicate]

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.

PHP mail() reaches GMail, Yahoo, but not other addresses

We have a confirmation script for our users, which uses the PHP mail() function. If I enter my own address (GMail or Yahoo) everything works perfectly. If however I enter the client's address, the function returns 1 but the email never reaches its destination. We checked spam but the email is not there either.
This is the PHP script I prepared:
$msg = "Body of the message";
$headers = "From: OUR TEAM <team#our_email.com>\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$sendmail = mail('some#address.com', 'Trial email (testing...)', $msg, $headers);
echo ("Sent mail = ") . $sendmail;
The return value is always 1.
Is there a way around this?
Thanks.

Form doesn't send info to email address (works on others though)

My client has a Wordpress content management system to which I added a simple contact form with a php form handler. The contact form sends the information by email correctly to all three of my email addressses, but when I change to my client's email address the email never arrives. I have run out of ideas where I could look for the problem. No it does not go to his junk mail folder. :)
Sounds like the email is being routed "internally" through your clients network and not out onto the internet. The chances are they have some restrictions on what machines can be used to send emails internally, or the mail routing system sees the internal email as being "different" and does something odd with it.
Try using (from a cli) :
echo "Testing " | mailx -"Test Subject Line" user#company.co.uk
What is the mail function that you are using? Do you attach a header to it? It sounds like it is being marked as spam from the exchange server. What I use (and have always worked for me) is something like this:
`
function mailme($sendto,$sendername,$from,$subject,$sendmailbody,$bcc="")
{
$subject = nl2br($subject);
$sendmailbody = nl2br($sendmailbody);
if($bcc!="")
{
$headers = "Bcc: ".$bcc."\n";
}
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=utf-8 \nContent-Transfer-Encoding: 8bit\n";
$headers .= "X-Priority: 3\n";
$headers .= "X-MSMail-Priority: Normal\n";
$headers .= "X-Mailer: PHP/"."MIME-Version: 1.0\n";
$headers .= "From: " . $from . "\n";
$headers .= "Content-Type: text/html\n";
mail("$sendto","$subject","$sendmailbody","$headers");
}
`

PHP Mail - Can't Receive On Certain Mail Servers

Using the php mail() function to send out emails when a user requests a login.
It was working fine last week, emails were being received by all my coworkers who share the same mail server for our company. Now however, the emails are not being received by that mail server, but received on others (comcast.net, uservoice.com, gmail.com, etc.) just fine.
No error from the php mail() function so the emails are being sent, just for whatever reason they are all of a sudden blocked by our mail server.
No settings have been changed to the php scripts or the mail server.
Any ideas??? I have tried everything!
<?PHP
$timestamp = date('Y-m-d H:i:s');
$to = 'james.hickman#MYCOMPANY.com';
$from = 'support#MYCOMPANY.uservoice.com';
$subject = 'Admin Test';
$message = 'Just a simple test message! - '.$timestamp;
$headers .= "Reply-To: ".$from."\r\n";
$headers .= "Return-Path: ".$from."\r\n";
$headers .= "From: ".$from."\r\n";
$headers .= "Organization: MYCOMPANY Support\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$headers .= "X-Priority: 3\r\n";
$headers .= "X-Mailer: PHP". phpversion() ."\r\n" ;
if(mail($to, $subject, $message, $headers, "-f ".$from))
echo "Success!";
else
echo "Failed";
?>
If you are able to send mail out to other services and just not your own server then the problem is not with php's mail function. Php's mail function just sends out mail and you yourself said that u are able to send mails to other hosts. So the problem is not as devious as it sounds. Try and check if your server is out of disk-space.

Mail generated in PHP going to spam [duplicate]

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";

Categories