PROBLEM SENDING: Bounce: Your message contains invalid characters (bare line feed characters)

I am running PHP List 3.4.7 on Windows Server 2012 with a localhost SMTP server (via PHP Mailer). Also tried labeling SMTP server directly in the PHPlist config file without a difference in the result.

I am getting a consistent bounce error with certain recipients warning of an inability to receive “bare linefeeds”. I can’t find any documentation or workarounds for this. This appears to happen with Office 365 recipients which probably means a problem for a significant number of people. Consistent issue over multiple versions of the PHPList software.

I don’t know how to get access to the email in its raw form to spot the problem. Are there basic steps I should take to resolve this with PHP List? I haven’t done anything to the code, etc. Nothing in the documents or config seems to speak to this issue at all.

Regards,
Enterfrize

@Enterfrize There are some places where phplist uses literal text or html which will probably use LF only, not CR LF.

One such is ensuring that the message has a <head> element, so ensure that your template does include a head element.

I think that sending through an SMTP server instead of using the php mail() function is more likely to have LF changed to CR LF by phpmailer.

I’m almost sure I solved it! I upgraded to PHP 7.X and updated PEAR as well. Sent message to troublesome email, and no bounce or bare linefeed reports (in fact, got notified that message was opened).

Regards
Enterfrize

I was wrong. I didn’t fix the problem. Just got the bounce message. I will check the element in the template.

Below is the template. I’ve tried both SMTP and the php mail() function (at least, I think that’s what I did because if you don’t put in an SMTP server, it should use the php mail function by default, right?)

<html>
<head>
	<title></title>
</head>
<body>
<div style="margin:0; text-align:center; width:100%; background:#EEE;min-width:240px;height:100%;"><br />
<a href="http://www.ifcsummit.com"><img alt="" src="https://services.tifca.com/uploadimages/image/IFCS-Logo-1_350.png" style="width: 350px; height: 103px;" /></a><br />
&nbsp;
<div style="width:96%;margin:0 auto; border-top:6px solid #369;border-bottom: 6px solid #369;background:#DEF;">
<h3 style="margin-top:5px;background-color:#69C; font-weight:normal; color:#FFF; text-align:center; margin-bottom:5px; padding:10px; line-height:1.2; font-size:21px; text-transform:capitalize;">[SUBJECT]</h3>

<div style="text-align:justify;background:#FFF;padding:20px; border-top:2px solid #369;min-height:200px;font-size:13px; border-bottom:2px solid #369;">[CONTENT]
<div style="clear:both">&nbsp;</div>
</div>

<div style="clear:both;background:#69C;font-weight:normal; padding:10px;color:#FFF;text-align:center;font-size:11px;margin:5px 0px">[FOOTER]<br />
[SIGNATURE]</div>
</div>
</div>
</body>
</html>

I read that a PHPMailer update may help, but I don’t think the current PHPMailer (6.X version) looks anything like what PHPList is using. Looks like I’m stuck!

@Enterfrize If you send through an smtp server, by specifying PHPMAILERHOST then line endings should be normalised by this code in PHPMailer/class.smtp.php

    // Normalize line breaks before exploding
    $lines = explode("\n", str_replace(array("\r\n", "\r"), "\n", $msg_data));

The code then appends CRLF to each line it sends

            $this->client_send($line_out.self::CRLF);

You can use smtp debug to try to see what the line endings actually are. Replace line 750 of file admin/sendemaillib.php by the following, then send a test message. The debug output will be at the top of the page

$mail->Debugoutput = function ($str, $level) {
    echo ord(substr($str, -2, 1)), ' ', ord(substr($str, -1, 1)), ' ', $str;
};

and enable smtp debug in config.php

define('PHPMAILER_SMTP_DEBUG', 2);

The line endings look to to me, e.g.

13 10 CLIENT -> SERVER: 
13 10 CLIENT -> SERVER: --b2_5cc4733f2aed9ecd9c9496f71d2695de
13 10 CLIENT -> SERVER: Content-Type: text/html; charset=us-ascii
13 10 CLIENT -> SERVER: 
13 10 CLIENT -> SERVER: <html><head>
13 10 CLIENT -> SERVER:         <meta content="text/html;charset=UTF-8" http-equiv="Content-Type">
13 10 CLIENT -> SERVER:         <meta content="width=device-width"/>
13 10 CLIENT -> SERVER:         <title></title></head><body><p>Hello</p>
13 10 CLIENT -> SERVER: 
13 10 CLIENT -> SERVER: <p>here is the body</p>

When I did the above, it sent the email to me normally without any debug info. This makes me wonder if indeed it is using the php mailer at all. How do I know that the php mailer is being used in my phplist config file? More precisely, how do I know which PHP file is being used for the mail-out process?

CORRECTION! When I renamed the sendmaillib.php file, the test email refused to go out, so it is being used for something.

Can you tell me what line 750 is supposed to originally look like? How and where will the debug material appear?

In the config file for PHPLIST there was no debug field so I created one from scratch - is that all that was necessary?

Just to add, I’m not a PHP programmer. I used to code in other stuff, but not PHP. Assume I don’t know every little step. :wink:

I thought I fixed it earlier, but I was way wrong. I thought maybe it was because the template was missing the <!DOCTYPE html> tag, but it made no difference.

I’m really stuck. I don’t understand why I’m the only one experiencing this problem.

Just a heads-up that I gave your instructions a second read. I’m not seeing any debug output at the top of the screen no matter what I do. Can you give more precise instructions on what is being replaced with what? I need to be certain I’m adjusting the right things. Again, I’m seeing zero debug info to work with.

@Enterfrize Sorry for not being clear. The line to replace is

$mail->Debugoutput = 'html';

the replacement code additionally shows the last two characters of each line sent out by phpmailer, 13 for a CR, 10 for a LF. You will need to view the html source of the resultant page to see a neater layout.

The line number I gave is probably wrong as it is affected by some other unrelated changes.
If you look in config_extended.php then there is an explanation of the setting but just adding it to config.php is correct.

I followed your instructions, the email sent, but I did not see any visible debug information. Should it be shown in the PHPList application? Is it supposed to be embedded with the email I receive? Where is it?

Can you share a screencap of the debug in action so I know what it looks like?

This is what the adjusted code section looks like:

// build the email
$mail = new PHPlistMailer($messageid, $destinationemail);

if ($isTestMail) {
$mail->SMTPDebug = PHPMAILER_SMTP_DEBUG;
$mail->Debugoutput = function ($str, $level) {
echo ord(substr($str, -2, 1)), ’ ', ord(substr($str, -1, 1)), ’ ', $str;
};
}

if ($forwardedby) {
$mail->add_timestamp();

@Enterfrize the debug information is at the top of the page