Few chars getting replaced with '=' in mail content in wp_mail - php

Whenever mails are triggered from wordpress site, a few alphabets are randomly getting replaced with '=' in the mail content. I have set the charset and content type in headers even then this weird error is coming. What could be the possible fix to this ?
Below is my code to trigger mails from wordpress site:
$footerText = "<br/><br/>
Regards,<br/>
ABC<br/><br/>
Note: This is an automated mail. Please do not reply to this message";
$post = get_post($postId);
$post_date = strtotime($post->post_date);
$author_email = get_the_author_meta( 'user_email', $post->post_author);
$headers = array();
$headers[] = 'Content-type: text/html; charset=UTF-8';
$headers[] = 'From: '.FROM_EMAIL;
//$headers[] = 'Bcc: '.$author_email;
$subject = "Request to share your expertise on - '".$post->post_title."'";
$post_title = $post->post_title;
$post_content = $post->post_content;
$post_url = get_permalink($post->ID);
$mail_message = "Your expertise would help solve complex business problems that would
help our associates solve our client problems faster.
Request you to share your expertise on the following post,
which has not been answered for over ".$days." days now.<br/><br/>
Post: <strong>".$post_title."</strong><br/>
Description: ".$post_content."<br/><br/>
Click <a href='".$post_url."'>here</a> to respond to the post.<br/><br/>
Thanks You!
".$footerText;
$hello_text = "Dear Expert,<br /><br />";
$full_message = $hello_text.$mail_message;
wp_mail('abc#gmail.com',$subject,$full_message,$headers);
Emails that i receive using this code is as follows:
Dear Expert,
Your expertise would help solve complex business p=oblems that would help our associates solve our Cli=nt(s) problems faster. Request you to share your experti=e on the following post, which has not been answered for o=er 8 days now.
Post: RFP for Business De=elopment,Functional Testing,Technology Expert,Perfecto,Healthcare,Medical =anagement,Mobile,Digital,North America This is Dynamic content, retrieved from database
Description: Customer is asking f=r RFQ to develop a new mobile app for care management application in AHM. =HM is a subsidary of Aetna Inc. This is Dynamic content, retrieved from database
Click here to respond to the post.
Thank you!
Regards, ABC
Note: This is an automated mail.=lease do not reply to this message
Totally confused on why random letters are getting replaced with '='.Kindly point out and suggest what is wrong with this

Commenting couple of return statements and replacing them as suggested in the below link on wordpress.org worked for me, now the mails are sent properly and the equal sign '=' issue is solved.
Fixed by making following changes in wp-includes\class-phpmailer.php
public function encodeQP($string, $line_max = 76)
{
// Use native function if it's available (>= PHP5.3)
if (function_exists('quoted_printable_encode')) {
//return $this->fixEOL(quoted_printable_encode($string)); commented this one
return quoted_printable_encode($string); // added this line
}
// Fall back to a pure PHP implementation
$string = str_replace(
array('%20', '%0D%0A.', '%0D%0A', '%'),
array(' ', "\r\n=2E", "\r\n", '='),
rawurlencode($string)
);
$string = preg_replace('/[^\r\n]{' . ($line_max - 3) . '}[^=\r\n]{2}/', "$0=\r\n", $string);
//return $this->fixEOL($string); commented this one
return $string; // added this line
}
Read more here: https://core.trac.wordpress.org/ticket/33815

Related

Getting Mail body In PHP

What I am doing:
First I am trying to get email and save the reply of user in my database.
For this I am using PHP imap method to get mail from my email address.
Code:
function get_email()
{
//define server, email , password
$server = '{server.example.com:143}INBOX';
$user_name = 'login';
$user_pass = 'password';
$mail = imap_open( $server , $user_name , $user_pass );
$headers = imap_num_msg($mail);//counting the no of msg
for ($i = 1; $i <= $headers ; $i++)
{
$body = imap_fetchbody($mail, $i ,1);
$body = explode(">",$body);
$body = $body['0'];
$body = substr($body, 0, -5);
echo "<pre>";
echo "/-/-/-/-/-/".$body."/-/-/-/-/-/";
echo "</pre>";
}
// close the connection
imap_close($mail);
}
Now:
The Result that i am getting from $body = imap_fetchbody($mail, $i ,$i); is this:
Okay What new in it.
On Thu, Feb 12, 2015 at 4:56 PM, admin wrote:
> My name is admin!
>
>
but only wanted a the msg body that Okay What new in it. . So I explode() the massage and get the first element of array and remove the last line.
Problem:
I could not remove last line the current result of this program Is:
Okay What new in it.
On Thu, Feb 12, 2015 at 4:56 PM, admin
Even I have add "/-/-/-/-/-/" symbol but the symbol are not showing.
Your approach is not ideal, and this answer will not be ideal either. Because frankly what you are trying to accomplish can be quite difficult, because previous messages in a thread on emails will be different depending on client used and you cannot trust the user either (the thread below the 'body' could have been altered by the user etc.)
Using explode by '>' is not ideal, because what if it is part of the message?
exploding by \n> is a no go too because a user might inline responses as #Michael_Berkovski said.
Anyways here is my solution:
$body = preg_replace('#(\n>.*?)+$#','',$body);
This will reduce the following:
This is the body
> And this is a comment within the body
Also just the body
>Previous messages
>here
>> Even indented who cares?
to:
This is the body
> And this is a comment within the body
Also just the body
For trying very hard I come to a solution that ask user to reply with '#' at the end of the massage. As I notice there are different types of replies from different mailing services but all services show reply first.
Code:
$msgno = imap_num_msg($mail);
for ($i = 1; $i <= $msgno ; $i++)
{
$body = imap_fetchbody($mail, $i ,1);
$body = explode("#",$body);
$body = $body['0'];
echo $body;
echo "<br>";
}
From this I got my desire result.

Yahoo! messenger API & PHP

So i have the API documentation, i have it working as far as logging me in. When i try to send an error the class just has return true so that does not help much. The IM is not being sent so i changed the class to return why it is not being sent.
> Fetching request token > Fetching access token > Signon as: {MY_ACCOUNT}#yahoo.com > {"error":{"code":-1005,"detail":"Invalid Argument Error","description":"Invalid Argument Error"},"code":-1005}
Trying to send the IM uses
$sendIm = $engine->send_message($toAddress, 'TEST');
print_r($sendIm);
I have tried
$toAddress = 'theirAddress';
AND
$toAddress = 'TheirAddress#yahoo.com';
Looking at http://developer.yahoo.com/messenger/guide/ch02.html shows that -1005 is a "bad argument", however there are only 2 passed into the IM function, to & msg, both of which are correct. Anyone else have this issue? Anyone with any ideas?
Ok, it is now figured out for anyone else who has this issue, in the class's "send_message" function
$postdata = '{"message" : '. $message. '}';
is WRONG and needs to be
$postdata = '{"message" : "'. $message. '"}';
Notice the quotes around $message. This is all it took! Simple typo in the API.

Foreign Characters in HTML Email

I wrote a script that takes HTML input from a web page and sends it out as an HTML email. For some reason there are foreign characters, usually exclamation points, showing up in the email that arrives in our inboxes that do not exist in the input. I've checked for hidden characters and there are none. The input is not being copied and pasted but directly entered. Here's a before and after example.
Input:
<p>Katherine Kemler, LSU flute professor, will perform at 7:30 p.m. Feb. 1 in Wattenbarger Auditorium. The performance is free and open to the public.</p>
Output: http://img42.com/LKEou
You can see the erroneous characters between Feb. and 1 and after Watt. I don't think it's the email client because it's the same in every client I've checked.
I've read some other questions around here that have led me to try things like using UTF-8 encoding instead of ISO-8859-1, using base64_encode() on the body, setting the content-transfer-encoding to 8bit but none of that has worked. I've read something about needing a line break after 998 characters but these exclamation points aren't showing up in way that suggests that to me. In my example above, one follows only ten characters after another. Here's my script:
<?php
if(!isset($_GET["id"])) return "<span class=\"text-error\">No ID specified.</span>"; //this should never happen
$id = $_GET["id"];
$ok = false;
$students = //redacted
$facstaff = //redacted
$studentsBCC = //redacted
$facstaffBCC = //redacted
$subject = "Tech Times for ".date("m/d");
$headers = "From: \"Tennessee Tech University\" <techtimes#tntech.edu>\r\n".
"Reply-to: no-reply#tntech.edu\r\n".
"MIME-Version: 1.0\r\n".
"Content-Transfer-Encoding: 8bit\r\n".
"Content-type: text/html; charset=UTF-8\r\n".//iso-8859-1\r\n".
"X-Mailer: PHP/".phpversion();
$resource = $modx->getObject("modResource", $id);
if(is_null($resource)) return "<span class=\"text-error\">Failed to get Resource $id</span>"; //this should never happen either
//get the template and insert the content
$body = $modx->getChunk("techtimes", array("copy"=>$resource->getContent(), "headerimg"=>$resource->getTVValue("headerImg")));
//check to see if this is a test run and if so reassign destination email address and empty BCCs
if(isset($_GET["email"])){
$facstaff = $_GET["email"];
$students = $_GET["email"];
$studentsBCC = "";
$facstaffBCC = "";
}
switch($id){
case 50: $ok = mail($facstaff,$subject,$body,$headers."\r\nBcc:".$facstaffBCC); break;
case 51: $ok = mail($students,$subject,$body,$headers."\r\nBcc:".$studentsBCC); break;
default: return "<span class=\"text-error\">Invalid or no ID specified for Tech Times.</span>"; //this, too, should never happen
}
if($ok){
$output = "<span class=\"text-success\">Tech Times for <strong>".(($id == 50) ? "Fac/Staff" : "students")." ($id)</strong> has been sent to <strong>".(($id == 50) ? $facstaff : $students)."</strong></span>.";
}else{ //this could happen if something goes wrong with the mailer
$error = error_get_last();
var_dump($error);
$output = "<span class=\"text-error\">Failed to send Tech Times!</span>";
}
return $output;
?>
I'm using MODx Revolution to format the output. I'm stumped.
Help?
Thanks!

Drupal 7 drupal_mail stripping out HTML?

I have a custom module that I'm trying to generate an HTML email from using the drupal_mail function (D7). Mail is coming through, and even shows text/html, however something somewhere appears to be stripping out the HTMl before it gets to an inbox.
First, in a function I'm building my title/body/other vars and sending to a custom function:
$body = "We thought you'd like to know that ".$fullname." has marked your project as completed.
<br /><br />
Please visit the link at <a href='http://".$_SERVER['HTTP_HOST']."/survey/customer/".$customer[0]->unique_id."'>http://".$_SERVER['HTTP_HOST']."/survey/customer/".$customer[0]->unique_id."</a> to take the survey.";
$returnMail = latch_send_mail('pro_realized',$customer[0]->customer_email,$user->mail,$title,$body);
Then I have the latch_mail latch_send_email functions:
function latch_mail($key, &$message, $params) {
$headers = array(
'MIME-Version' => '1.0',
'Content-Type' => 'text/html; charset=UTF-8; format=flowed',
'Content-Transfer-Encoding' => '8Bit',
'X-Mailer' => 'Drupal'
);
foreach ($headers as $key => $value) {
$message['headers'][$key] = $value;
}
$message['body'][] = $params['body'];
$message['subject'] = $params['subject'];
}
and
function latch_send_mail($key,$to,$from,$title,$body,$headers='') {
$params['body']=$body;
$params['subject'] = t($title);
return drupal_mail('latch', $key, $to, language_default(), $params, $from,TRUE);
}
I would expect the emails to come through with my a tags and br tags, but it comes through like this:
We thought you'd like to know that John Doe has marked your project as completed. Please visit the link at http://latch.local/survey/customer/34c91b8883cd70b32c65feb7adf9c393 [1] to take the survey. [1] http://latch.local/survey/customer/34c91b8883cd70b32c65feb7adf9c393
Somehow it's taking my links and turning them into footnotes while removing the br tags completely.
Any help you can provide would be appreciated. Thanks!
Out of the box, Drupal can't send HTML email. In order for Drupal to support HTML email you need the HTML Mail module. http://drupal.org/project/htmlmail Once you have that all HTML should be sent as such.
Here's an alternative method with a complete explenation. First of all, install and enable the Mime Mail module. You can read the README.txt for complete instructions on how to use it. I'll give you the short version.
You need to enable Mime Mail for your module. You can do this using hook_enable or hook_update_N in example.install:
function example_enable() {
mailsystem_set(array(
'example_examplekey' => 'MimeMailSystem',
));
}
When you go to admin/config/system/mailsystem you will see that a new entry has been added for your module:
Example module (examplekey key) class
MimeMailSystem
Now you don't need to specificy any text/html headers anymore, Mime Mail takes care of this. So you don't need this:
$headers['Content-Type'] = ...
If you want, you can add $message['plaintext'] to your mail for a non-HTML alternative, but this is not required.
That's it!

Microsoft outlook and PHP email fail to be a valid email it goes straight to the junk box if i change email contents to hello world works. rubish err

Nightmare Episode 1
I put 21 hours today to solve this. But i failed, asking experts to have a look, checked almost PEAR all possibilities but this Microsoft Outlook never gives up. What is this secret ?
Microsoft Outlook 2010 as receives as junk email when i put junk filter to "High". If i send another email with my same account from Google it goes to Inbox.
What is the problem with this Outlook ? I tried to follow multipart/alternative or multipart/mixed or multipart/relative but all Same.
My server log shows: 100% ok no spam not blacklist, all clear
Dec 8 15:42:30 www postfix/smtp[15250]: C99908162: to=, relay=mail.andmylab.com[01.01.01.01]:25, delay=0.25, delays=0.07/0.01/0.08/0.09, dsn=2.0.0, status=sent (250 OK id=1PQQqL-0001b6-TA)
My blacklist: www.whatismyipaddress.com shows no black list all green
- I can send to Google or to my own domain and other domain without any problems.
My code: its generating exactly multipart/alternative where i am following RFC standards
/* DB details */
$config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/cloude.ini', 'production');
define("DBHOST", $config->resources->db->params->host);
define("DBUSER", $config->resources->db->params->username);
define("DBPASS", $config->resources->db->params->password);
define("DEFAULT_DB", $config->resources->db->params->dbname);
define("MAILER_TABLE", "mail_queue");
/* 1 --------------------- PEAR!! */
require_once "Mail/Queue.php";
require_once 'Mail/mime.php';
require_once 'Mail/mimePart.php';
/* 2 --------------------- DB */
$db_options['type'] = 'db';
$db_options['dsn'] = 'mysql://' . DBUSER . ":" . DBPASS . "#" . DBHOST . "/" . DEFAULT_DB;
$db_options['mail_table'] = MAILER_TABLE;
$mail_options['driver'] = 'mail';
/* Step ------------------ 1 */
$mail_queue =& new Mail_Queue($db_options, $mail_options);
$from = "validguy#lul.be";
/* Step ------------------ 2 */
$mime =& new Mail_mime($crlf = "\n");
$mail =& Mail::factory($mail_options['driver']);
/* Step ------------------ 3 Plain text and Html */
$data->mode = 'html';
if ($data->mode=='html')
{
/* A <--------------- part */
$params['content_type'] = 'multipart/alternative';
$email = new Mail_mimePart('', $params);
/* B <--------------- part */
$email = $email->encode();
$email['headers']['Mime-Version'] = '1.0';
$email['headers']['Subject'] = $fix;
$email['headers']['From'] = $from;
//Zend_Debug::dump($email);
// exit;
/* C <--------------- part */
$mime->setTXTBody('Test');
$mime->setHTMLBody($txt2);
/* D <--------------- part */
$body = $mime->get();
$hdrs = $mime->headers($email['headers']);
} else if($data->mode=='both') {
// later... for multipart/relative
} else {
// later... for inline
}
/* Step 4 - done */
$mailResult = $mail_queue->put($from, $row->email, $hdrs, $body, 0,true,$nres[0]['id']);
//$mailResult = $mail_queue->put($from, $row->email, $email['headers'], $email['body'], 0,true,$nres[0]['id']);
if(!PEAR::isError($mailResult)){ $m++; } else { $n++; }
}
}
/* Relax........ */
echo "Records transfered: " . $m . "<br/>";
echo "Records failed to transfer: " . $n . "<br/>";
Nightmare Episode 1 (FOLLOW UP)
SPF fix (zone file setting, required)
- Go to all SPF testing sites, and check what there wizard saying
Fix PTR (zone file setting, required)
Dkim proxy (zone file setting, required)
Prepare two version Plain text and Html
Check message headers from working emails that arrives without any problem to your inbox like (Google/Yahoo and others top companies), and compare that towards yours
Do not trust Microsoft Outlook 2010 or Old version, because in junk filter (high) its also written similar, it may not be a spam that must be a business issue, to make us stupid. And put us in nightmare to solve those issues.
If you don't agree in those TOP reasons, please advise and bit it, this is what i learned and trying to share, because its very annoying as a developer, if you don't have any answer for this RUBISH EROR, caused by Microsoft Outlook 2010.
First of all its Microsoft itself. To really overcome with this issue you can take action such as:
MailChimp: very nice, after pulling all my hair out why it does not work, i found that they got some nice templates with special secret inside, but any way, i just customized it, and it works, i can hit straight crap Outlook express "Inbox" even its high spam filtered.

Categories