Email sent from shared hosting is blocked. Is there a way to avoid this?

on my website I have a PHP script that automatically sends an order confirmation to my customers. My website domain is registered with the company that also hosts my website. I'm having trouble sending email using the mail () function to some email accounts ... a lot of my users have linked me saying they never received my automatic email address! So this is a very big problem!

The accounts giving me more trouble are comcast.net, uol.com, mchsi.com and more! I contacted the support center of these email service providers asking them to also remove my ip from the block list.

The email header looks like this:

$header = "Sender: $from_mail\n";
$header .= "From: Account <$from_mail>\n";
$header .= "Reply-To: Account <$from_mail >\n";
$header .= "Content-Type: multipart/mixed; boundary=$mixed_boundary\n";
$header .= "Mime-Version: 1.0\n";
$header .= "X-Mailer: PHP/".phpversion()."\n";

$body = "\n--$mixed_boundary\n";
.
.
.
.
$body .= "\n\n--$mixed_boundary--";

mail($to, $subject, $body, utf8_encode($header), "-f$from_mail");

      

Is there something I can try to avoid this problem? Does someone know where I can find out what is the IP address of the server used to deliver the email read the PHP mail () function?

Thank you for your responses!!!


Hello,

so far, some email services like Comcast keep blocking my IPs saying my mail server is sending spam ... I asked to be removed from the block list but their system keeps blocking them! I don't know what else I can do ... I followed your suggestions and the code looks like this:

$md5 = md5(date('r', time()));
$mixed_boundary = "PHP-Mixed-$md5";
$alt_boundary = "PHP-Alt-$md5";

$header = "Sender: $from_mail\r\n";
$header .= "Errors-To: $from_mail\r\n";
$header .= "From: account <$from_mail>\r\n";
$header .= "Reply-To: $from_mail\r\n";
$header .= "Content-Type: multipart/mixed; boundary=$mixed_boundary\r\n";
$header .= "Mime-Version: 1.0\r\n";
$header .= "X-Mailer: PHP/".phpversion()."\r\n";

$body = "\n--$mixed_boundary\n";
$body .= "Content-Type: multipart/alternative; boundary=$alt_boundary\n";
.
.
.
.
$body .= "--$mixed_boundary\n";
$body .= "Content-Disposition: attachment filename=\"...\"\n";
$body .= "Content-Type: application/octet-stream; x-unix-mode=0644; name=\"...\"\n";
$body .= "Content-Transfer-Encoding: base64\n";
.
.
.
.
$body .= "\n\n--$mixed_boundary--";


mail($to, $subject, $body, utf8_encode($header), "-f$from_mail");

      

Suggestions?

Thanks again!

+2


source to share


6 answers


Your message headers are not valid according to RFC2822 Internet Message Format .

From 2.1 General description:

Messages are divided into character strings. A line is a series of characters that are delimited by two carriage return and linear feed characters; that is, a carriage return (CR) character (ASCII value 13) followed immediately by a line feed (LF) character (ASCII value 10). (A carriage return / carriage return pair is usually written as "CRLF" in this document.)

As I pointed out in my comments, the reason your email can work with most mail servers is because they can be liberal in what they accept. However, there may be some mail servers that will discard your messages as they are not RFC2822 compliant.



EDIT: Although the use of "\ r \ n" is used in the PHP documentation for the mail () function, there is some discussion as to whether this is really the right thing to do .

The mail () function will bind to the local sendmail (8) command (or whatever is configured in sendmail_path), and the line ending may be handled differently depending on which implementation of the mail transfer agent is being used. From what I understand, sendmail (8) should be fine with "\ r \ n", but qmail (7) , for example, will replace "\ r \ n" with "\ r \ r \ n", which, will probably break the message.

All of this happens before the email is delivered to its final destination, so it can be easily checked if the final lines are being processed correctly by sending one custom email message built with "\ r \ n" and checking that all headers are present.

See also: RFC2822 , PHP mail () function , sendmail (8) , qmail (7)

+3


source


You can email yourself and check the headers. This will give you an idea of ​​the path the email might take, but nothing really prevents other domains' email from going the other way.

All in all, those big ISPs have really powerful spam filters, so sending them from a shared host will be tricky. If you can get your own IP address and send mail from there, that will probably help. Then you can customize SPF records . No guarantees, but it will definitely take you out of the commercial spam chasm.



You can also dig in the link text and some other anti-spam services and see if you are doing anything else wrong.

Asking customers to add your address to their spam whitelist probably won't hurt either.

+3


source


Let me explain the battle you are facing. Forget about technical details for a minute. There are hundreds of email providers out there. The big ones are Yahoo, Gmail, AOL, Hotmail, etc. If you are blocked on any of these services, your business could be badly hit.

These email providers are extremely concerned about spam and have gone to the extreme to combat spam by blocking any messages that might be spam. You may never get spam complaints, but if another business in your shared hosting plan gets spam complaints, you will be committed. It doesn't matter how you configure your application, if you are on a suspicious spam IP, your messages will be sent to the spam folder.

Even if you have your own server, you will still have problems. Over time, if you send emails, some of the recipients will end up in the spam button. It is a fact of life and there is nothing you can do to prevent it.

The only solution is to send you email. Companies like Aweber or iContact are involved in email delivery. They have relationships with all major email providers and work to ensure that your messages reach the recipients' inbox. You no longer need to worry about contacting Yahoo or Gmail because someone hit the spam button. You can focus on more important things.

+3


source


I found that in some cases, help with settings Return-Path

, Sender

and Errors-To

.

+2


source


I noticed that with my Linux hosting server I have to replace all occurrences of CRLF with LF in both additional headers and mixed / alternate headers. About what the PHP documentation says:

"If no messages are received, try using only LF (\ n). Some low-quality Unix-quality mail agents will automatically replace LF with CRLF (which doubles the CR if using CRLF). This should be a last resort as it does not comply with the" RFC 2822. "

I tried to send mail (only with "\ n") to my personal account and I searched for "\ r" and "\ n" in the raw message ... each line ends with CR and starts with "\ n"!

QUESTION: As the PHP mail () documentation says, I am using the wordwrap () function to shorten the line length to 70 characters. Is there a workaround to allow the email client to display the message with its original formatting rather than as a column where each line is no longer than 70 characters?

ANSWER [SOLUTION]: I decided to set up the print quotes as Content-Transfer-Encoding:

$body .= "Content-Transfer-Encoding: quoted-printable\n";
$body .= "Content-Type: text/plain;\n\tcharset=utf-8;\n\tformat=flowed;\n\tdelsp=yes\n";

$body .= "\n" . quoted_printable_encode($message);

      

The quoted_printable_encode () function is only available since PHP 5.3, the implementation fits on the page.

0


source


Use PHPMailer ( http://phpmailer.worxware.com/ ) to create email messages. Maybe it's not an IP, but something else. There are many things where spam filters react to allergic reactions (like missing message ID, etc.). Also, with PHPMailer you have the option to send your emails by mail () or if it doesn't work due to problems with shared hosting via SMTP via another host (like Gmail).

0


source







All Articles