I am currently having struggle sending an email from php:
$header = "MIME-Version: 1.0\r\n";
$header .= "Content-type: text/html; charset=utf-8\r\n";
$header .= "From: jan#XXX.at\r\n";
$header .= "Reply-To: jan#XXX.at\r\n";
$header .= "X-Mailer: PHP " . phpversion();
mail("receiver#yyy.at", "Subject", "Body", $header);
The Problem is that on receiver side, the mail has the following sender adress:
xxx#hostname.at where hostname.at is the host the PHP script runs on.
xxx.at gets replaced by hostname.at all the time. I'm running Plesk and PHP 8.0.3. Any ideas?
Turned out that plesk has a feature called "Fix incorrectly set sender for outgoing mail under Tools & Settings > Mail Server.
unchecked that, works.
Related
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.
My code looks like this
$to = "mymailid#gmail.com";
$subject = "sample subject";
$body = "<div> hi hi .. </div>";
$headers = "Reply-To: The Sender <mymailid#gmail.com>\r\n";
$headers .= "Return-Path: The Sender <mymailid#gmail.com>\r\n";
$headers .= "From: The Sender <mymailid#gmail.com>\r\n";
$headers .='X-Mailer: PHP/' . phpversion();
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
mail($to, $subject, $body,$headers)
I have sent the suitalbe header in my mail function. Everytime when i run this code, my mail will go to the spam folder in my gmail account.. How do i avoid my mail going to spam folder?
It can fixed by passing complete header information informing the mail provider as the sender is a trusted domain (https://en.wikipedia.org/wiki/DomainKeys_Identified_Mail) also some DNS settings involved.
You can find the detail information here:
http://www.velvetblues.com/web-development-blog/avoid-spam-filters-with-php-mail-emails/
https://www.digitalocean.com/community/questions/email-goes-to-spam-gmail-php
This question already has answers here:
Prevent sent emails treated as junk mails using php mail function
(14 answers)
Closed 9 years ago.
I used this tutorial for sending mail :
http://www.velvetblues.com/web-development-blog/avoid-spam-filters-with-php-mail-emails/
My code looks like this :
$headers .= "Reply-To: The Sender <sender#sender.com>\r\n";
$headers .= "Return-Path: The Sender <sender#sender.com>\r\n";
$headers .= "From: The Sender <senter#sender.com>\r\n";
$headers .= "Organization: Sender Organization\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"
mail("recipient#recipient.com", "Message", "A simple message.", $headers);
I am using localhost(MAMP PRO) for sending mail.
But mail goes to spam folder.How to send mail which goes to inbox.Please guys help me out from this,i spend a lot of time on it.
Which folder an email goes into depends mostly on the domain & ipaddress from which the email is coming from and the email service provider. If your domain/ip is trusted by the service provider it will not be spammed.
Also, after setting a few emails as "Not Spam" from that domain, your email service will no longer spam the emails
there are more than one reason ur email goes to spam ...
1 - make sure that the "from email" is actually the email u are sending the emails from .. i mean dont use any other false "from Email"
2- you have to keep the message body simple as possible . dont use so much html tags and css experssions , and also try to use tables
I've searched and searched for a solution to this but to no avail.
I'm using the php mailer to send out a mixed text / html email, encoded in utf8. Here's the relevant code:
$headers = "From: $fromPerson\r\n" .
"Content-Transfer-Encoding: 8bit\r\n".
"Reply-To: $fromPerson\r\n" .
"Content-Type: multipart/alternative; boundary=". $mime_boundary_header. "\r\n" .
"X-Mailer: PHP/" . phpversion();
$message = "$notice_text
--$mime_boundary
Content-Type: text/plain; charset='UTF-8'
Content-Transfer-Encoding: 8bit
$textEmail
--$mime_boundary
Content-Type: text/html; charset='UTF-8'
Content-Transfer-Encoding: 8bit
$htmlEmail
--$mime_boundary--";
//mb_detect_encoding($message) returns UTF-8
$mail_sent = #mail( $to, $subject, $message, $headers);
The messages contain Spanish along with those tricky characters. The emails display fine in gmail, hotmail (online outlook), mac mail, phones etc. but not in Windows live mail or Microsoft outlook.
If I manually set the default font in Windows live Mail to utf8 the message displays correctly, but otherwise it does not. If I forward the email from another client to outlook or windows live it displays fine as well.
I could find work arounds I'm sure, but am I missing something? I don't want to rely on the receivers knowing how to change the encoding of the message, so is there something I need to add to the email to prompt these clients to recognise the encoding?
I apologise if this has been dealt with elsewhere, and I'll appreciate any advice. It looks like I should just go ahead and use PHPMailer to see if that fixes the problem, but out of personal curiosity it would be interesting to learn why this is happening...
I'm not sure that the ' wrapping the charset are necessary, or even correct. Try removing them:
Content-Type: text/plain; charset=UTF-8
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=UTF-8\r\n";
$headers .= "From: example#example.com\r\n";
$headers .= "Reply-To: example#example.com\r\n";
A modification to Riko's answer makes for a little cleaner code.
$header_array = [
"MIME-Version: 1.0",
"Content-type: text/html; charset=UTF-8",
"From: example#example.com",
"Reply-To: example#example.com"
];
$headers = implode("\r\n", $header_array);
Is it possible to manipulate the date header using PHP's mail function/sendmail (website server is linux so I believe it's using sendmail underneath)?
I'm trying to test error handling of a (windows based) email checker, and need to generate an invalid date header in a message, but when I send my message using php mail, even though I am including a custom Date header, it seems to get overridden by the mail server and my custom header ignored. I'm guessing I might need an additional parameter for sendmail to tamper with that header, but I can't seem to find what that parameter would be, or whether this is even possible.
Here is what I am sending (with the personal domain info removed)
$headers = "From: ..................\r\n";
$headers .= "Message-ID: <" . md5(uniqid(time())) . "#..................>\n";
$headers .= "MIME-Version: 1.0\n";
//$headers .= "Date: ".date("D, d M Y H:i:s") . " UT\n"; //a valid header for comparison
$headers .= "Date: Tuesday\n"; // intentionally bogus email header
$headers .= "Reply-To: ..................\n";
$headers .= "Return-Path: ..................\r\n";
$headers .= "X-Priority: 3\r\nX-MSMail-Priority: Normal\n";
$headers .= "X-Mailer: PHP/".phpversion()."\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\n";
$headers .= "\n";
$success=mail($to, $s_subject, $s_emailmsg, $headers);
Assuming you wrote an email checker that runs via procmail, an easier way might be to construct an email message yourself and send that directly to the test script via standard input.
It's easier to write unit tests that way as it bypasses any interference by other mail servers. When you do follow this, make sure that the first line starts with MAIL FROM xx#yy.com.
I am trying to send new system generated password using mail() in php. The thing is I am able to send it to yahoo but when I use gmail or hotmail I dont receive any emails although the function returns true. Following is the function:
if(mail($to,$subject,$body))
{
return true;
}
else
{
return false;
}
It probably ends up in the spam folder look there. If its there make sure your email headers are perfect.
You could look into librairies for what you want to achieve. Zend_Mail has everything you could need to connect to gmail and others.
If you are getting the mail successfully through yahoo, you should also post the headers that are coming through from yahoo here in the question. My bet is you will need to include a "from field" also to get through on hotmail, gmail, etc...
Your problem might be the antispam filters. E-mails sent from PHP are usually marked as spam by the mail servers and end up deleted or in the spam can.
You can Google for "php mail spam" to get some hints of how to work around this issue.
Maybe you're on a shared server and the IP is banned/blocked due to spamming by other users (websites) of your server.
Try adding SPF records.
Ensure that your envelope-FROM (a.k.a. return path) is set to a valid email address that you have access to. If you're not seeing the message in the spam folders, it should be getting bounced; the bounce message may offer a clue as to why the mail is not getting through.
I would try to include your own headers in your mail function
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "Date: ". date('r'). " \r\n";
$headers .= "Return-Path:youremail#domain.com\r\n";
$headers .= "Errors-To:youremail#domain.com\r\n";
$headers .= "From:youremail#domain.com <youremail#domain.com>\r\n";
$headers .= "Reply-to:youremail#domain.com \r\n";
$headers .= "Organization: YourOrg \r\n";
$headers .= "X-Sender:youremail#domain.com \r\n";
$headers .= "X-Priority: 3 \r\n";
$headers .= "X-MSMail-Priority: Normal \r\n";
$headers .= "X-Mailer: PHP/" . phpversion();
mail($to,$subject,$body,$headers);
Try checking if your mailserver ip is blacklisted anywhere?
http://www.mxtoolbox.com/blacklists.aspx
If not, try harder with the headers that are being sent with the mail.