Solved

Php Generated Emails and Bare LFs SMTP Errors

Posted on 2003-12-02
2
338 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

785 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