Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send € or € sign in email subject using phpMailer class

Tags:

php

phpmailer

I am sending email using PHPMailer.

I want to send price in subject, e.g "Bid of Price 460 € has been placed".

I used € and € in subject but it doesn't display properly. It shows &euro instead incase of €

What should I use to solve this?

Here is my code:

$mail = new PHPMailer(true);
$mail->IsMail();
$body = $mailBody;
$mail->CharSet = "text/html; charset=UTF-8;"; 
$mail->IsHTML(true);
$mail -> AddAddress( $email, '' );  

$mail -> SetFrom( '[email protected]', 'Support Fretbay.com');
$mail -> Subject = 'Bid of Price 460 € has been placed';
$mail -> AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically
$mail -> MsgHTML($body);
$mail -> Send();
like image 653
StormTrooper Avatar asked Jan 26 '15 12:01

StormTrooper


People also ask

How do I send as in Gmail?

In the "Send mail as," click Add another email address. In the window that opens, enter the name you want recipients to view. Enter the email address alias you've set up for email forwarding. Confirm that "Treat as an alias" is marked, and click Next step.


2 Answers

Subjects can't contain html entities, so € won't work. You have to use charset that contains euro symbol, and set $mail->CharSet property. And sure, your char must use this charset too:

$mail->CharSet = "UTF-8";
$mail->Subject = 'Bid of Price 460 € has been placed';
like image 114
Marek Avatar answered Sep 24 '22 17:09

Marek


Its important that the euro sign is UTF-8 to be displayed correctly.

A simple solution is to use mb_encode_mimeheader, to be 100% sure.

$subject = "Here is €500!";
$subject = str_replace('€', mb_encode_mimeheader('€', 'UTF-8'), $subject);

Works well with PHPMailer and PEAR::Mail

like image 21
Joakim Ling Avatar answered Sep 24 '22 17:09

Joakim Ling