开发者

extra newlines in plain text emails sent via sendgrid

开发者 https://www.devze.com 2023-03-11 00:16 出处:网络
We send emails in plain text from PHP using CodeIgniter (v1.7) and also PHPMailer (v5.1). Current production setup uses a cheapie SMTP relay, plan is to switch to a CritSend or SendGrid. We are testin

We send emails in plain text from PHP using CodeIgniter (v1.7) and also PHPMailer (v5.1). Current production setup uses a cheapie SMTP relay, plan is to switch to a CritSend or SendGrid. We are testing the options now from a Rackspace Cloud server.

When we use SendGrid SMTP all "\r\n" newlines in the emials end up being doubled up, so end up as "\r\n\r\n".

All works fine when using CritSend SMTP and also two other SMTP servers.

SendGrid tech support don't think it is anything to do with their system, but have heard of another client with the same issue and apparently it got solved with a config change on the client's side.

Anyone experienced this?

This isn't critical for us as CritSend works well and seems as good as SendGrid on features, so we will go with them. BUT being a curious type, I just can't let this go :-)

Usual setup: PHP script -> sendmail/Postfix -> external SMTP relay -> ....

To test the different SMTP relays I change the postfix config, only SendGrid gives the extra newlines all other SMTP options work fine. If I dump the email via CodeIgniter email class debug function it looks fine before it goes to postfix.

Alternate setup: PHP script (either CI mail class or PHPMialer) -> external SMTP relay -> ....

To test the different SM开发者_JAVA百科TP relays I change the SMTP settings in the CI email config or PHPMialer config. Only SendGrid gives the extra newlines all other SMTP options work fine.

There aren't all that many options to play with as far as I can see. I tried "utf-8" and "ISO-something or other", all newlines on our side are "\r\n"...... seesm like some very obscure bug somewhere.

Any ideas?


OK, a bit more experimenting and these settings make plain text emails go trough SendGrid nicely from PHPMailer:

    $mailer->CharSet    = "utf-8";
    $mailer->LE         = "\r\n";
    $mailer->Encoding   = "quoted-printable";
    $mailer->WordWrap   = 80;

The "quoted-printable" part is the key.


What worked for me was using actual line-breaks in the PHP text as follows:

    // Prepare email
    $email = array(
        'api_user'  => App::emailAPIUser(),
        'api_key'   => App::emailAPIPwd(),
        'to'        => $email,
        'subject'   => 'Thank you for entering ' . App::name(),
        'html'      => $email_body,
        'text'      => '

Thank you for entering Competition. 

You are now in the running to WIN your prices valued at $6000. 

Winners will be notified of their status by the 14th February 2012. 

Good luck!',
        'from'      => 'competitions@company.com'
    );
0

精彩评论

暂无评论...
验证码 换一张
取 消