How do I get PHP to send strings as UTF-8 and parse html code too, via email?

This is the code that is being sent via email:
$_['email_text_1']      = 'NAME OF COMPANY: <a href=""></a>';
$_['email_text_2']      = 'offre prodotti e servizi a condizione vantaggiose per le famiglie sostenedno il mondo delle associazioni e del volontariato secondo formule innovative. L\'iscrizione è completamente GRATUITA e non comporta nessun impegno da parte tua.';

Open in new window

This is the php code that is sending the email:
class ModelCatalogTellafriend extends Model {
	public function sendMail($data) {
		$data['email'] = $this->customer->getEmail();
        $data['name'] = $this->customer->getFirstName();
		$customer_id = $this->customer->getId();
         $friend = $data['sendto'];
		 $this->notifyFriend($friend, $data['email'], $data['name']);

	public function notifyFriend($friend, $email, $name) {
		$customer_id = $this->customer->getId();
		$encoded_string = base64_encode($customer_id);
		$subject = sprintf($this->language->get('email_subject'), $name);
		$message = $this->language->get('email_greeting') . "\n\n";
		$message .= sprintf($this->language->get('email_text_1'), $name, $email) . "\n\n";
		$message .= sprintf($this->language->get('email_text_2'), $name) . "\n\n";
		$message .= $this->config->get('config_name') . ': ' . $this->config->get('config_url'). "\n\n";
		$message .= sprintf($this->language->get('email_invite'))."\n\n";
		$message .= sprintf($this->language->get('email_signup')). "".$encoded_string. "\n\n";
		$mail = new PHPMailer();

		$mail->IsSMTP();                       // telling the class to use SMTP

		$mail->SMTPDebug = 1;                  
		// 0 = no output, 1 = errors and messages, 2 = messages only.

		$mail->SMTPAuth = true;                // enable SMTP authentication
		$mail->SMTPSecure = "tls";              // sets the prefix to the servier
		$mail->Host = "";        // sets Gmail as the SMTP server
		$mail->Port = 587;                     // set the SMTP port for the GMAIL

		$mail->Username = "";  // Gmail username
		$mail->Password = "xdgsgdsgsdg";      // Gmail password

		$mail->CharSet = 'windows-1250';
		$mail->SetFrom ('');
		$mail->AddBCC ('');
		$mail->Subject = $subject;
		$mail->ContentType = 'text/plain';

		$mail->Body = $message; 
		// you may also use $mail->Body = file_get_contents('your_mail_template.html');

		$mail->AddAddress ($friend, $name);     
		// you may also use this format $mail->AddAddress ($recipient);

		        $error_message = "Mailer Error: " . $mail->ErrorInfo;
		} else 
		        $error_message = "Successfully sent!";

	public function notifyAdmin($data) {
		$subject = $this->language->get('email_admin');
		$message = sprintf($this->language->get('email_sender'), $data['name'], $data['email']) . "\n\n";
		$message .= $this->language->get('email_recommend') . "\n";
		$message .= $data['sendto'] . "\n";
		$mail = new Mail();
		$mail->protocol = $this->config->get('config_mail_protocol');
		$mail->hostname = $this->config->get('config_smtp_host');
		$mail->username = $this->config->get('config_smtp_username');
		$mail->password = $this->config->get('config_smtp_password');
		$mail->port = $this->config->get('config_smtp_port');
		$mail->timeout = $this->config->get('config_smtp_timeout');
		$mail->setText(html_entity_decode($message, ENT_QUOTES, 'UTF-8'));

Open in new window

I need those two strings to come via email with the html code parsed and also the accented letters (like "è") showing correctly.

How can I achieve this? Which lines should I edit?

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Marcus BointonCommented:
You're sending your email having told it to expect content using a windows-1250 charset; if you're not providing your data in that charset (either by it being submitted originally in that charset or via conversion), then it will appear corrupt. I would suggest you do everything in UTF-8, it's just much simpler that way.
badwolfffAuthor Commented:
yes, thanks, I got that already. What I don't know is HOW to do it :)

Can you help?
badwolfffAuthor Commented:
Do I just change that line?
$mail->CharSet = 'windows-1250';
if so,
what do I change it to?
Marcus BointonCommented:

    $mail->CharSet = 'utf-8';

But you need to know that the data you're giving it is also in UTF-8 - it doesn't convert it for you.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ray PaseurCommented:
Consistency from beginning to end is important in any application that uses UTF-8 (and all of them will use it soon).  Some of the background you need to understand is in this article.  It's an increasingly common issue for PHP software, since PHP changed its posture toward UTF-8 recently.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.