Incorrect Email(without html) is sending through Mailgun - php

I am using Mailgun API based extension in Expression engine CMS When i disable the Mail-gun its sending perfect html mail but when I enable Mailgun its sending Email like in this manner:
This is a multi-part message in MIME format.
Your email application may not support this format.
--B_ALT_565e9f7740811
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
HELLO this is a message
--B_ALT_565e9f7740811
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable
<b>HELLO</b> this is a message
--B_ALT_565e9f7740811--
I type only once "HELLO this is a message" in this manner:
<b>HELLO</b> this is a message
But its showing two times in the email please resolve this issue.

I had so much headache with sending though an API I ended up buying Escort (https://devot-ee.com/add-ons/escort) and it simply worked perfectly and saved a lot of time making it worth it. I use it with Mandrill, but it supports yours.
Hope this kind of answer is allowed, as I know it isn't directly solving your problem.

Related

Gmail displaying plain text instead of HTML

Situation
I have a script that is downloading emails from a Gmail account, tweaking the content, and re-sending out the emails.
Problem
Whenever I create an email with an embedded image, Gmail displays the plain text version of the email and the embedded image appears like a regular attachment.
Tested
If I use a different client, the image displays properly. If I forward the email from Gmail to a different client, the image displays properly. Multi-part emails that have regular attachments, or that have both plain text and html parts display properly - as long as they don't have an embedded image.
Email format
From what I can see, the format of the email is correct, but I've pasted it below, trimmed for brevity & privacy. The 2 things I notice is that the boundary appears to be properly set, and the img src cid: matches the Content-ID of the image.
MIME-Version: 1.0
Content-Type: multipart/related;
boundary="_=_swift_1575407655_756d311b6808cc9e07d75ccca0ed9b6c_=_"
--_=_swift_1575407655_756d311b6808cc9e07d75ccca0ed9b6c_=_
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
This email has been sent to a Mailing List. You can approve or reject it a=
t [URL here]
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
[image: noice.gif]
-----------------------
[Signature here]
--_=_swift_1575407655_756d311b6808cc9e07d75ccca0ed9b6c_=_
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable
<p>
This email has been sent to a Mailing List. You can approve or reject =
it at [URL here]</p>
<hr />
<div dir=3D"ltr"><div><img src=3D"cid:7f82a31e4f084e8f0a25edd913ed3aa2#swif=
t.generated" alt=3D"noice.gif" width=3D"474" height=3D"244"><br></div><div>=
<div dir=3D"ltr" class=3D"gmail_signature" data-smartmail=3D"gmail_signatur=
e"><div dir=3D"ltr"><div><div dir=3D"ltr"><div><div dir=3D"ltr"><br><br>---=
--------------------<br>[signature here]<br></div>=
</div></div></div></div></div></div></div>
--_=_swift_1575407655_756d311b6808cc9e07d75ccca0ed9b6c_=_
Content-Type: image/gif; name=noice.gif
Content-Transfer-Encoding: base64
Content-ID: <7f82a31e4f084e8f0a25edd913ed3aa2#swift.generated>
Content-Disposition: inline; filename=noice.gif
R0lGODlh2gH0APcAAAgDBRGJG5ZKGsDGB8lNFJJsGkkIBs+nLgnCM4lPZODnDqdMGo4rCVGIKs5q
[... bunch of base64 encoded stuff]
BFGgAUsAEvjkAlQgq/drOjfkFKdEETNBxl3bpi5lBYEAADs=
--_=_swift_1575407655_756d311b6808cc9e07d75ccca0ed9b6c_=_--
PHP code
Here is the PHP code that generates the Mailer object - which is a wrapper around Swiftmailer, and is used to do the actual sending:
$Mailer = new Mailer($subject_prepend.$this->subject);
// Simply a wrapper. Calls $this->Message->setBody($body,'text/plain');,
// where $this->Message is an instance of Swift_Message
$Mailer->setBody($plaintext_prepend.$this->plaintext);
$html_body = $html_prepend.$this->html;
if(count($this->Attachments)){
foreach($this->Attachments as $Attachment){
if($Attachment->isEmbedded()){
$image = \Swift_Image::fromPath($Attachment->getPath())->setDisposition('inline');
$cid = $Mailer->Message->embed($image);
//$cid = $Mailer->embedPath($Attachment->getPath());
$html_body = str_replace('cid:'.$Attachment->cid, $cid, $html_body);
}
else{
// calls $this->Message->attach(\Swift_Attachment::fromPath($path));
$Mailer->addAttachmentPath($Attachment->getPath());
}
}
}
// calls $this->Message->addPart($body,'text/html');
$Mailer->addHTMLBody($html_body);
The commented out line is how I was originally embedding the image, but it had the same result.
-
Is this some Gmail magic that's failing me, or is the email misconfigured somehow?
Edit
I managed to get the email sending properly with PHPMailer. The only difference I can see is that PHPMailer starts with:
MIME-Version: 1.0
Content-Type: multipart/alternative; boundary="b1_6hukH7nTGJu6fpr5tpXob5uQE7wXivW0oMppPNbwOi4"
Content-Transfer-Encoding: 8bit
where Swiftmailer starts with
MIME-Version: 1.0
Content-Type: multipart/related; boundary="_=_swift_1575416351_99d22ee774049152f712bc5ae65340fb_=_"
ie: PHPMailer uses multipart/alternative rather than multipart/related, and sets Content-Transfer-Encoding.
Also, all textual parts of SwiftMailer's email was `Content-Transfer-Encoding: quoted-printable' whereas PHPMailer didn't set that header.

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

imap_fetchbody can't handle mails sent with phpmailer?

I am sending some emails with phpmailer with the regular example on their website.
the email is sent, and it arrives perfectly to the sent address.
after the mail is sent, I am saving the email to my sent items folder with imap_append, using the info of this answer Sent mails with phpmailer don't go to "Sent" IMAP folder
and in third place, I am creating a custom made webmail which reads my imap folders.
the problem is that I can't get the html body of the email sent correctly.
When I open the mail on sent items on thunderbird, or my phone, the body is shown perfectly.
but when I try to get the html body with php_imap functions I can't make it!!.
I created an isolated file to fetch the body of the msg like this:
$body = imap_fetchbody($conn,3392,1,FT_UID);
that returns this:
--b1_9db4e4310d1b141cbec79dd7de22f70b Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit á é í ñ Ñ REMOVED CONTENT --------------------- klfasjdkl adj skldj klfdj akfdsj lkfdasjfkl dasjf --b1_9db4e4310d1b141cbec79dd7de22f70b Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit á é í ñ Ñ
REMOVED CONTENT
---------------------
klfasjdkl adj skldj klfdj akfdsj lkfdasjfkl dasjf --b1_9db4e4310d1b141cbec79dd7de22f70b--
If I try
$body = imap_fetchbody($conn,3392,1.2,FT_UID);
don't get anything
If I try
$body = imap_fetchbody($conn,3392,2,FT_UID);
don't get anything, it seems that PHPMailer creating the emailbody in a way that imap_fetchbody can't handle?
thank you

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.

PHP send MIME emails...doesn't work anymore

I just switched from a shared server to a virtual dedicated. The whole site works, but my mail forms have quit sending MIME emails the way they used to.
What used to appear before the server switch:
hallo fwend
What appears now in the emails (appears as though my client doesn't support MIME):
Content-Type: multipart/alternative; boundary="==DL-
bound_b08bcfabdc459ae7e87e493a984115b3"
This is a multipart MIME message from
your friends at Example.com. If you
are reading this, it seems we have a
message to deliver, but your mail
client is not set to receive these
types of messages. We are sorry for
the inconvenience :(
--==DL-bound_b08bcfabdc459ae7e87e493a984115b3
Content-Type: text/plain;
charset=iso-8859-1
Content-Transfer-Encoding: 7bit
hallo fwend
Is there some switch in PHP or something that I need turned on to send MIME?
It look like the headers are send in the body part of the message.
I had this problem a while back.
Possible causes are:
1. EOL
I used "\r\n" as eol for the MIME headers (following the spec)
, but the (shared)server wanted an "\n"
2. Last header
Some mail server add some headers of their own. If the last header end with "\n" and the mail server could also mess thing up.
3. Empty header
An empty header which causes a "\n\n" in the $headers will corrupt the headers. The "\n\n" aka "empty line" marks the end of the headers part of a email (or the start of the body)

Categories