recipient name encoding in phpmailer - php

Please I need a help because this problem is really killed me ...
When I send an Email with PHPMAILER using localhost on Wamp server with a non English text ,The receiver shows the Email as is (The body and subject) but TO name is shows as a numbers and hashes(symboles) , This name was got from POST[]
Now, if i write a text directly to a variable then it received as is ($variable='Arabic name';) this sends correctly(the name TO is true).
This what i got when getting the name from POST!
from:correct in any language<my#gmail.com>
reply-to: Information <info#example.com>
to: "محمد" <my#gmail.com>
I don't know why the receiver name is converted to symbols like that.
$mail->CharSet = 'UTF-8';
$mail->Encoding = "base64";
And as i mentioned above ALL Email elements(body,subject and sender name) are correct.

You can try using html_entity_decode to translate that back to a normal string.
$normalString = html_entity_decode($_POST['to']);

Related

How to use emoji in email subject line, send via PHPMailerClass

We are trying to send email with Emoji in subject line using our Email Api which is using PHPmailer class and powerMTA port25 for relay.
surprisingly when Email sent from our Email Api reachs yahoo and when we look into "view raw message" our subject looks like:
=?utf-8?Q?=F0=9F=91=89_Overtake_The_Year_End_Price_Drop.?=
what we sent was:
👉 Overtake The Year End Price Drop
On the other hand when look into email sent from some random ESP it's "view raw message" appears as what they had sent:
Subject: 👉Updates on Your Pre-Approved Loan offer
Please help to understand where things are getting wrong.
Set PHPMailer to use UTF-8, then go ahead and use it:
$mail->CharSet = 'utf-8';
$mail->Subject = '👉 Overtake…';

Email should come under same convestaion

I am sending email using php mailer and email is going fine to the inbox
but next time when i reply back instead of email coming to under same conversation it create a new email even it should show all the email subject
any one has an idea ?
The email you send via php must have a header
Reply-To: <from-email-address>
From: <from-email-address>
as well as a
To: <destination-email-address>
header line for it to appear as a conversation thread.
Also the subject line should be the same or be the same with a prepended 'Re: '

PHPMailer 5.1 sends duplicatie mails when adding more than 1 receiver

I'm using PHPMailer for a while now and never really had any problems, but last week I installed one of my CMS on a website and the client insisted on having 2 e-mails receiving the contents of the contact form of his website.
Ok, no problem I thought, just adding an e-mail address using the $phpmailer->AddAddress() function. However, adding a second receiver is causing PHPMailer to send the mail twice to both receivers. I tried adding a third receiver to see if I got it three times, but this didn't change anything. So adding 2+ receivers is causing PHPMailer to send the message twice to all receivers.
There's nothing strange in my code. It's a basic PHPMailer example:
$mail = new PHPMailer();
$mail->AddReplyTo("name#yourdomain.com","First Last");
$mail->SetFrom('name#yourdomain.com', 'First Last');
$mail->AddAddress("info#address.com");
$mail->AddAddress("info#address.nl");
$mail->Subject = "PHPMailer Test Subject via mail(), basic";
$mail->Send();
I've ran out of options. I have absolutely no clue where it's going wrong.
Thanks in advance
--
Just some random thought: I noticed the mailer is defaulted by iso-8859-1 and my site is running utf8. Can there be a "silent" redirect by the server itself?
//EDIT, that ^^ solved my problem
//EDIT2:
Ok, it did not.. today the script worked fine (just 1 mail with 2 receivers) but a moment ago the strange behavior started again. Any tips?
// Solution:
ok, I feel quiet stupid! The answer Zulkhaery Basrul came closest to the actual problem! This is what happened: I was sending an e-mail to multiple addresses in the "to" field. For example:
To: A, B, C
Both A/B are my own adresses. In outlook I had some message rules to put e-mails with certain addressees inside a specific folder. Both A and B had this rule.
When I recieved my e-mail, both mails contained both mailaddresses in the to-field. Causing both of the mails to meet the rule requirements for both rules. Thus keeping the original in one folder and creating a copy in the other (twice).
Thanks for thinking tho :)
You can use $SingleTo property.
From PHPMailer docs:
$SingleTo
Provides the ability to have the TO field process individual emails,
instead of sending to entire 'TO addresses'
$mail = new PHPMailer();
$mail->SingleTo = true; //will send mail to each email address individually
$mail->AddReplyTo("name#yourdomain.com","First Last");
$mail->SetFrom('name#yourdomain.com', 'First Last');
$mail->AddAddress("info#address.com");
$mail->AddAddress("info#address.nl");
$mail->Subject = "PHPMailer Test Subject via mail(), basic";
$mail->Send();
Try to add after
$mail->send();
$mail->ClearAddresses();
Ok, if someone runs into this problem like I did:
My website runs in utf-8, PHPMailer uses iso-8859-1 by default. Somehow the script is run in both charsets causing duplicates. Changing the charset in the class.phpmailer.php file to utf-8 solved the problem!
I think these will do the job :)
$mail->SingleTo = true;
$mail->CharSet = "UTF-8";
I tried everything, UTF8 / BOM check on all files, SingleTo-property, CharSet-property.
It didn't work.
I used the "View Details" function from Gmail and saw that my duplicate mails were sent without a subject.
So, I ended up with a very, very dirty fix.
I put this DIRECTLY below the first line of the send function in the class file:
public function Send() {
if ($this->Subject == "") {
return true;
}
// ... rest of code...
}
I ran into the same problem. The one and only right answer is $mail->ClearAllRecipients()
When I used the accepted answer BCC mails were being sent to all recipients.
SingleTo Is not a good idea. It only works with "sendmail" or "mail" transports, not with SMTP. If you use SingleTo with SMTP, this parameter is just ignored without any error or warning, and you may get duplicates.
According to the authors of the library, SingleTo is planned to be deprecated in the release of PHPMailer 6.0, and removed in 7.0. The authors have explained that it's better to control sending to multiple recipients at a higher level: "PHPMailer isn't a mailing list sender". They tell that the use of the PHP mail() function needs to be discouraged because it's extremely difficult to use safely; SMTP is faster, safer, and gives more control and feedback.
But SMTP is incompatible with SingleTo -- that's why the authors of PHPMailer will remove SingleTo, not SMTP.

Getting only a certain part of an email body using imap_body

I have mails where I need to obtain the body via PHP imap functions and then storing it in the database. These mails a send from a response system. I use this code to fetch the body of the email
$bodyText = imap_fetchbody($mbox,$v,1.2);
if(!strlen($bodyText)>0){
$bodyText = imap_fetchbody($mbox,$v,1);
}
This works perfectly but also includes the original message body, is there a way to only obtain the reply.
The whole email body looks like this
**This is a test
--
Kind Regards,
-----Original Message-----
From: -------------
To:--------------------------
Subject: You have received a reply to your enquiry
New System
Date: Tue, 5 Jul 2011 16:24:28 +0200
Good day,
You have received the following reply to an enquiry you made
-------------------------------------------------------------------------------------------------
test3
--------------------------------------------------------------------------------------------------
To reply to this comment please click on the Reply To button and add the message you wish to send.**
Is there a way to get only the body of the message without the ORIGINAL MESSAGE USING IMAP FUNCTIONS OR other PHP functions?
There is a blog post here: http://www.damnsemicolon.com/php/php-parse-email-body-email-piping that addresses the issue. It uses commonly-known email client reply formats to make a best-guess at what the reply body is. That's as good as you can get, given that you can't control the email clients being used.
Just a note, the linked code uses the from and to name/email to better parse the email address. You can get those values like so:
$headerInfo = imap_headerinfo($mbox,$v);
$fromEmail = $headerInfo->from->personal;
$fromName = $headerInfo->from->mailbox . "#" . $headerInfo->from->host;
$toEmail = $headerInfo->to->personal;
$toName = $headerInfo->to->mailbox . "#" . $headerInfo->to->host;
Edit: the link seems to be dead, here's the google cache: http://webcache.googleusercontent.com/search?q=cache:5MxzHXFU5TkJ:www.damnsemicolon.com/php/php-parse-email-body-email-piping+&cd=1&hl=en&ct=clnk&gl=ca
have you tried a
substr($wholeMessage, 0, strpos($wholeMessage, 0, "-----Original Message-----"));
this will cut the message from the beginning up to where the ----Original Message--- string starts. dirty, but may server your needs
EDIT: I'm assuming you only have one mime part.. if you have several, you can just save the ones you need

Zend Mail sending with headers shown in body and header section in mail clients

I am using Zend Framework to send mail.
It's doing something very odd, the content type, content dispostion, MIME version and content type encoding are all showing up in the header section (under the subject) of the email in GMail and in Outlook.
The content of the email was also being included twice in the email, once as plain text and once as HTML. I stopped this by just using setBodyText() instead of using setBodyHtml() too. I had seen somewhere that you can use both. Now I just use setBodyText() like this
$mail = new Zend_Mail('utf-8');
$mail->addTo("mail#mail.com");
$mail->setSubject("Registration info");
$mail->setFrom('do-not-reply#mail.com', "A Name");
$mail->setBodyText($this->view->render('emails/register.phtml'));
$mail->send();
This has been solved. It was an error with the host receiving the email. The fact it was in Outlook or GMail made no difference as the error was with the host.

Categories