Solved

Php Generated Emails and Bare LFs SMTP Errors

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
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 count occurrences of each item in an array.

747 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

12 Experts available now in Live!

Get 1:1 Help Now