Avoiding exceeding 500 limits exceeded the error when sending letters

I am using the PHPMailer library integrated into Joomla for the email component in Joomla. It works very well, however I have a problem with users using the script with 1and1 mail servers. They may receive errors like this:

2012-06-14 18:20:34 u65913791 1x1et0-1RocCH2xzU-00qzkq EE transaction error after sending a text message: msmtp.kundenserver.de [172.19.35.7] Line limit exceeded

Another example from another user:

SMTP error from the remote mail server after data completion: host mx00.1and1.co.uk [212.227.15.134]: 500 Linear limit exceeded

The linear limit is not about how many lines, but how many characters are actually used in one line, which 1 and 1 is limited to 10,240 characters (response support), which is actually 10 times more than what is required in RFC 2822 .

I assume that the problem is caused by using the β€œwrong” line separators when sending emails so that all email reaches the email server as one line. I assume that I need to insert line breaks in my script, since PHPMailer does not.

Currently, I just get the HTML content from the WYSIWYG editor and put it in a PHPMailer object:

// snip, $mail2send is the JMail instance, which inherits PHPMailer
$mail2send->setSubject($mail->subject);
$mail2send->IsHTML(true);
$mail2send->setBody($mail->body);   
// snip

How can I insert suitable line breaks?

+5
source share
3 answers

: HTML . , , , .

, HTML-, :

/* HTML-tag-safe wordwrap
 * from http://php.net/manual/de/function.wordwrap.php
 * by nbenitezl[arroba]gmail[dot]com
 */
function htmlwrap(&$str, $maxLength=76, $char="\r\n"){
    $count = 0;
    $newStr = '';
    $openTag = false;
    $lenstr = strlen($str);
    for($i=0; $i<$lenstr; $i++){
        $newStr .= $str{$i};
        if($str{$i} == '<'){
            $openTag = true;
            continue;
        }
        if(($openTag) && ($str{$i} == '>')){
            $openTag = false;
            continue;
        }
        if(!$openTag){
            if($str{$i} == ' '){
                if ($count == 0) {
                    $newStr = substr($newStr,0, -1);
                    continue;
                } else {
                    $lastspace = $count + 1;
                }
            }
            $count++;
            if($count==$maxLength){
                if ($str{$i+1} != ' ' && $lastspace && ($lastspace < $count)) {
                    $tmp = ($count - $lastspace)* -1;
                    $newStr = substr($newStr,0, $tmp) . $char . substr($newStr,$tmp);
                    $count = $tmp * -1;
                } else {
                    $newStr .= $char;
                    $count = 0;
                }
                $lastspace = 0;
            }
        } 
    }

    return $newStr;
}
-1

chunk_split. , , ( 76 ).

,

$mail2send->setSubject($mail->subject);
$mail2send->IsHTML(true);
$mail2send->setBody(chunk_split($mail->body));  
+5

, base64 , . QP US-ASCII 8- / .

Of course, if your data is HTML, and otherwise it is safe for SMTP, just adding line terminators, where you otherwise have a space, is a bit of a fragile solution (are you sure you don’t have the original From line in anywhere, etc.?)

0
source

All Articles