Can't remove the X-Priority header while sending mail - php

I'm sending mail and using the wordpress SMTP plugin, however I have a problem that each time I send mail, on the debugging output I see the X-Priority header being sent which makes my MQS to drop with SpamAssassin.
I've set $phhmailer->SMTPDebug=false; and setting priority to null but it doesn't change anything.
The part of debug output looks like this:
["MIMEHeader":protected]=>
string(443) "Date: Tue, 5 Apr 2016 08:44:48 +0000
Return-Path:
To: web-z4CIb1#mail-tester.com
From: Example
Subject: WP Mail SMTP: Test mail to web-z4CIb1#mail-tester.com
Message-ID: <2edb8cb56706f6d09a29b49a66cf1ff0#example.com>
X-Priority:
X-Mailer: PHPMailer 5.2.7 (https://github.com/PHPMailer/PHPMailer/)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

After quite a bit of poking around I managed to fix the issue by opening up the phpmailer class file, and commented out the following line:
$result .= $this->headerLine('X-Priority', $this->Priority);
This removed the X-Priority header completely.

If X-priority is removed from the header the email will be handled as priority 2 (normal). Instead of removing the header item, could you set it to 2?
You should be able to unset the header by using $mail->Priority = null;
according to this closed issue over at GitHub.
There can be other things affecting your spam score as well, not only the empty Priority variable.

Setting the $mail->Priority = null; is the correct solution (or do not set it at all as the default is null). However, in order for it to work you will also need to make sure you have a version of PHPMailer that has been updated with this patch.

Related

PHPMailer - forward email to group

I have a need for everyone in my organization to send emails to everyone else in the group.
As there are hundreds of members, and the membership changes often, it is not practical to use the traditional CPanel email forwarding method. So I thought I would pipe the email to a php script, get all the members’ email addresses from the database (checking to make sure the original sender was also in the database) and send on the email to all members using PHPMailer.
I parsed the header in the PHP script to get the From, Subject (adding these of course to PHPMailer), Content-Type, and boundary. Then I collected the actual email message in a variable $message including the lines that say (in this case)
“This is a multi-part message in MIME format.
--------------3D4FAACFC2C069EFCDAE6DC6, etc. (This is of course in text format.)
Just before the PHPMailer Send command, I included:
$mail -> IsHTML(false);
// (I also tried not including this command at all – no change)
$mail->Body =$message;
$mail->addCustomHeader("Content-Type", $content_type . " boundary=" . $boundary);
$content_type and $boundary are the variables I parsed from the original header
As this is still in development, I sent the email to my address only. It was received and displayed properly (both the plain and html as usual), but was marked as Spam – the received Header had the Subject already marked as Spam so I assume PHPMailer did it.
I noticed on the received Header that my custom header appeared correctly:
Content-Type: multipart/alternative; boundary="------------3D4FAACFC2C069EFCDAE6DC6"
The received header also had another Content-Type: text/plain; charset=iso-8859-1 after the above which I assume PHPMailer added. Maybe the two Content-Types is what triggered the Spam tag. I then tried adding $mail->header_remove ('Content-Type'); after the Body call and before addCustomHeader, but the additional Content-Type: text/plain; charset=iso-8859-1 was still in the received header and it was still marked as Spam.
I am using PHPMailer version 5.2.22, and using
$mail->IsSMTP();
, $mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
I can’t continue to unsuccessfully experiment forever as I am afraid sending lots of Spam emails will get me in trouble, so I am hoping someone can tell what I am doing wrong, or even if my overall strategy is flawed. I wish also there was a way to get the header that PHPMailer is going to use before it actually sends out the mail.
Note: my organization is a charitable group with little money, so we can't afford paid SMTP's. I've tried using the free versions of some on the market (not for the above project) but given you are using a shared IP with many others using the free service you often get emails kicked back because others sharing your IP have been Spam tagged
Thanks
This is the entire header (I deleted some of the content just to keep this note a bit brief) that I received to my personal email (b...#....com) from my "forward email" script which uses everybody#....org as the originating address. You can see the Content_Type I added to PHPMailer via $mail->addCustomHeader("Content-Type", $content_type . " boundary=" . $boundary);(which is the multipart.. line) and the one PHPMailer itself added (text/plain...). The email was received fine and displayed properly except for the Spam added to the Subject line:
From - Sat Mar 25 12:51:13 2017
STUFF
Return-Path: <everybody#....org>
Received: from dnvrco-pub-iedge-vip.email.rr.com ([107.14.70.244])
by dnvrco-fep06.email.rr.com
(InterMail vM.8.04.03.24 201-2389-100-172-20151028) with ESMTP
id <20170325165112.EUNA23395.dnvrco-fep06.email.rr.com#dnvrco-pub-iedge-vip.email.rr.com>
for <bmadder#...>; Sat, 25 Mar 2017 16:51:12 +0000
Return-Path: <everybody#....org>
Received: from [173.205.126.142] ...
Received: from ecbiz194.inmotionhosting.com .....
Date: Sat, 25 Mar 2017 12:51:01 -0400
To: b...#....com
From: everybody#....org
Message-ID: ...
Content-Type: multipart/alternative; boundary="------------3D4FAACFC2C069EFCDAE6DC6"
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
X-OutGoing-Spam-Status: No, score=-1.0
X-AntiAbuse:...
X-Get-Message-Sender-Via: ecbiz194.inmotionhosting.com: authenticated_id: everybody#....org
X-Authenticated-Sender: ecbiz194.inmotionhosting.com: everybody#....org
X-Source:
X-Source-Args:
X-Source-Dir:
X-Authority-Analysis: v=2.1 cv=Od5ldUnY c=1 sm=1 tr=0 p=tHMjoff1TzQA:10 a=BPsZ5WN3F+ptBTNoNLYonA==:117 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=9+rZDBEiDlHhcck0kWbJtElFXBc=:19 a=6Iz7jQTuP9IA:10 a=FqPqrT7mAAAA:8 a=wuaQj91YKeLcW_I7NZUA:9 a=FtJ_xtNkBE-qfxEx:21 a=wPNLvfGTeEIA:10 a=yozH4VhRfl4A:10 a=M3AHoUkWFckA:10 a=fZGknuNN1LOydenUCIb6:22
X-Cloudmark-Score: 100
X-RR-Connecting-IP: 107.14.64.106:25
Subject: SPAM: Lots of work today
X-Brightmail-Tracker: AAAAARZYL6Q=
X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrDqMTGxcIABLocC65FGFx/aGGx78B3FgdGj+Mv3jMFMEZx+OWXKAQXJOYmcGT07L7AVsBQAaIaGBlWMSqUlBYbF2cUJxYVF6RWGJjrpacW6xVX5ibmlaQm6yXn525ihJq+g3H7RZlTjJJS4ry3512LEBIoBpqYUQpUVxRfVJqTWvyKUZyDUUmYNxcky5OZV1KcmQ6TkeBgUhLhNdl4JUKIt7gkESEl1cDY81CZ25t3k/zUd21bd90/typmy6NtErw+Xs/YlXtk7atb4j4+/t6yoHDeJ3uN/kP1P7LrIiY5fFipZfynvvPJzbNfz943kPtyweqk3Tn/vpOfGIosVIpPxHht7j+Rl24XEH2vJa1o/q3fJRonvyxi6D4x60xlW8M/o0oLBlvjw4672ZjKQg2UWIozEg21mIuKEwGcu2V6TwEAAA==
This is a multi-part message in MIME format.
--------------3D4FAACFC2C069EFCDAE6DC6
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
This is the text message
--------------3D4FAACFC2C069EFCDAE6DC6
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: 8bit
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<p>This is the text message <br>
</p>
</body>
</html>
--------------3D4FAACFC2C069EFCDAE6DC6--
I now have the solution. Rather than using the line of $mail->addCustomHeader("Content-Type", $content_type . " boundary=" . $boundary);, I appended the variable $boundary to the variable $content_type and used $mail->ContentType = $content_type; My mail forward script now works perfectly with the Spam label no longer an issue. The header that is sent to the final recipients no longer has duplicate Content-Types listed in the MIME part

Sending mail with php: Header gets broken

I use the following code to send a mail:
$recipient="mymail#example.com";
$body="<html><body>This is magic</body></html>";
$subject="hi folks!";
$thisMail="sender#example.com";
$replyHeader = "MIME-Version: 1.0\r\nContent-Type: text/html; charset=UTF-8\r\nFrom: ".$thisMail. "\r\nReply-To: ".$thisMail."\r\n";
mail($sender, "Re:".$subject, $body, $replyHeader);
The mail is sent, but when I open it in a client mailer, the header seems to be broken. Everything after the first New Line (\r\n) is shown in the mail. Also some other header-contents are displayed. So the visible body of the mail looks like this in a mail client:
Content-Type: text/html; charset=UTF-8
From: sender#example.com
Reply-To: sender#example.com
Envelope-To: mymail#example.com
X-UI-Filterresults [... lots of stuff]
<html><body>This is magic</body></html>
What is going wrong there?
One (out of many) examples that show it "should" work that way: http://css-tricks.com/sending-nice-html-email-with-php/
Rather than relying on the mail function there are some really great libraries out there that handle headers, attachments, content and sending for you.
One of them - which is used by Laravel and other frameworks - is SwiftMailer, you should check it out.
They have some good documentation on setting headers too!
Honestly, you'll gain a lot from making use of the library and not reinventing the wheel.

I can't get line returns in CodeIgniter plain text email messages

I've been struggling with this one. No matter what I do, I cannot get new lines, empty lines, or line returns to show up in any email message I generate with CodeIgniter (v 2.1.3).
Within my Controller function:
$message = "Line one.\r\n\r\n" .
"Line two.\r\n\r\n" .
"Line three.\r\n\r\n";
$subject = "My Subject Line";
$this->load->library('email');
$config['newline'] = "\r\n"; // does not matter when I leave this out
$config['crlf'] = "\r\n"; // does not matter when I leave this out
$this->email->initialize($config);
$this->email->from('system#mydomain.com', 'my system');
$this->email->to('me#gmail.com');
$this->email->subject($subject);
$this->email->message($message);
$this->email->send();
echo $this->email->print_debugger();
I've changed no settings or defaults, other than what I've shown above.
The "source" of the message looks just like this print_debugger() output...
User-Agent: CodeIgniter
Date: Sun, 24 Mar 2013 17:46:47 -0400
From: "my system"
Return-Path:
Reply-To: "system#mydomain.com"
X-Sender: system#mydomain.com
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <xxxxxx#mydomain.com>
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary="B_ALT_514f74472bd26"
=?utf-8?Q?My_Subject_Line?=
This is a multi-part message in MIME format.
Your email application may not support this format.
--B_ALT_514f74472bd26
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Line one.
Line two.
Line three.
--B_ALT_514f74472bd26
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable
Line one.
Line two.
Line three.
--B_ALT_514f74472bd26--
HOWEVER, the problem is that the actual message is rendering in all email clients as the following.
Line one.Line two.Line three.
Why are my "\r\n" being ignored?
This is a very simple message and I'd prefer to not have to use any html options. As per CI documentation, the mailtype preference should be defaulting to text.
Where am I going wrong here?
The CodeIgniter 2 documentation appears to be wrong.
On this page, it contains a listing of available preferences.
Note this one, mailtype...
Preference Default Value Options
mailtype text text or html
Adding the following setting fixed this problem, so clearly it's not the "default value"...
$config['mailtype'] = 'text';
My thread at CI asking about this discrepancy in the docs:
http://ellislab.com/forums/viewthread/234296/
EDIT:
Entire problem was being caused by the following code within my Ion Auth configuration file...
$config['email_config'] = array(
'mailtype' => 'html',
);
It seems codigniter is sending your email as both text/html and text/plain. Most email clients render html version of emails and in html white spaces are broken down to a singe space. Check if codeigniter has an option to turn off sending an html version or just use <br> instead of \r\n.

Issue with headers using fsockopen for ESMTP connection on php

I send email without a problem but when i look on the headers i can see that before of the ones i create appears "X-Mailbox-Line: " and i have no idea why, does any one knows why ?
An example:
X-Mailbox-Line: From : <contacto#nidida.com>
Reply-To: <contacto#nidida.com>
MIME-Version: 1.0
Usually the X-* headers add added by receiver SMTP, so your code it's not the problem!

Codeigniter: Looking for an explanation of email->set_newline(..) functionality

I am currently developing a website with the help of codeigniter and the ion auth library.
I am trying to use ion auth's standard functionality to reset a users password.
In the library there are 2 functions:
forgotten_password($identity)
forgotten_password_complete($code)
Both functions (in case validation goes through) send an email to the user. The functions themselves work, but the emails i receive are broken. The emails header is displayed as a part of the emails body. This is how a broken email looks:
Date: Fri, 18 Nov 2011 23:36:32 +0100
From: "Example.com" <admin#example.com>
Reply-To: "admin#example.com" <admin#example.com>
X-Sender: admin#example.com
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <4ec6ddf0d26a3#example.com>
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary="B_ALT_4ec6ddf0d26b9"
This is a multi-part message in MIME format.
Your email application may not support this format.
--B_ALT_4ec6ddf0d26b9
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
New Password for test_user
Your password has been reset to: 0774b65f5e
--B_ALT_4ec6ddf0d26b9
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable
<html>
<body>
<h1>New Password for test_user</h1>
=09
<p>Your password has been reset to: 0774b65f5e</p>
</body>
</html>
--B_ALT_4ec6ddf0d26b9--
However I was able to track down the line which is causing the trouble:
$this->ci->email->set_newline("\r\n");
When I comment out this line (in both functions mentioned above), the emails I receive when I reset a users password are fine.
Can someone explain to me the purpose of this line and wether or not it is a good idea to solve this problem by just commenting the line out.
I also found 2 questions
Problem sending email with Codeigniter - Headers sent in the message body
https://stackoverflow.com/questions/6740672/mime-format-email-breaking-sporadically-in-hotmail-php-codeigniter
referring to the same or at least a similar problem. As they are fairly old and haven't been answered yet, I created a new one. Hope no one minds.
Different operating systems use different characters to determine a new line (the place at which a line breaks to the next line.) In HTML, the equivalent is the <br> tag. Some (old? Mac) traditionally use \r, some (Unix) traditionally use \n, and others (Windows) traditionally use both (\r\n).
Codeigniter defaults to \n (see documentation), but the writer of ion auth overrode that to use \r\n, which is the standard.
So, the program parsing the email headers (which at my best guess is *nix-based) sees the non-Unix-standard \r\n line and starts spitting the headers out as part of the body.
To the best of my knowledge, you'll get by fine with just \n, which is why Codeigniter defaults to it. Every instance I've seen of people with troubles have been people using \r\n and getting the same problem you're having.
In CI, that setting defaults to '\n' when you comment that line out. The setting depends on the mail server that's being used by PHP. Sometimes postfix and some other servers will replace \r\n with \r\r\n causing errors, so in these cases it's best to just use \n, since the standard (RFC 822) requires \r\n.

Categories