Solved

Php Generated Emails and Bare LFs SMTP Errors

Posted on 2003-12-02
2
335 Views
Last Modified: 2012-06-22
Hi Everyone,

I am not a Php developer, however some of my clients PHP based scripts to generate emails get refused by various smtp relays, responding with links to http://cr.yp.to/docs/smtplf.html.

I understand the problem, but my question in short, is What is the best way to fix this issue?

Does the latest version of PHP fix this issue?  We are running a slightly older version.  Whilst some clients can probably edit their scripts directly, others may be using scripts like phpbb, which they cannot address.

Thanks.
0
Comment
Question by:Jimby_Aus
2 Comments
 
LVL 7

Accepted Solution

by:
petoskey-001 earned 500 total points
ID: 9876526
The issue is that SMTP requires that lines end with Carriage Return then LineFeed.  This is ascii - 13 followed by ascii 10.  Unix/Linux uses only the line feed.  

When the script is creating the message it has only the line feed in it.  You can use the following process before your mail command to fix it.

Old command used to look like this...

   mail( $EmailToAddress, $EmailSubject, $EmailMessage, $EmailHeaders );

Modify the lines to look like this...

//    mail( $EmailToAddress, $EmailSubject, $EmailMessage, $EmailHeaders );

    $newMessage = ereg_replace("\n","\r\n", $EmailMessage);
    $newMessage = ereg_replace("\r\r\n", "\r\n", $newMessage);

    $newHeaders = ereg_replace("\n","\r\n", $EmailHeaders);
    $newHeaders = ereg_replace("\r\r\n", "\r\n", $newHeaders);

    mail( $EmailToAddress, $EmailSubject, $newMessage, $newHeaders );

This assumes they are using the built-in PHP command to send mail.  If their app uses direct telnet to the SMTP server then things won't be this easy.  You should be able to search the PHP files for the "mail(" line to figure out where to perform this replacement.  

More popular scripts like phpBB should not have this problem.

0
 
LVL 1

Author Comment

by:Jimby_Aus
ID: 9902030
Thanks, Ill test this out, then finalise the thread.
Jimby.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
WordPress TK Title 8 23
mysql update statement effect only some rows 4 26
php string masking 4 27
PHP warning 4 28
Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now