Solved

Php Generated Emails and Bare LFs SMTP Errors

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
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 dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

830 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