I try to use PHPMailer to send registration, activation. etc mail to users:
require("class.phpmailer.php");
$mail -> charSet = "UTF-8";
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "smtp.mydomain.org";
$mail->From = "name#mydomain.org";
$mail->SMTPAuth = true;
$mail->Username ="username";
$mail->Password="passw";
//$mail->FromName = $header;
$mail->FromName = mb_convert_encoding($header, "UTF-8", "auto");
$mail->AddAddress($emladd);
$mail->AddAddress("mytest#gmail.com");
$mail->AddBCC('mytest2#mydomain.org', 'firstadd');
$mail->Subject = $sub;
$mail->Body = $message;
$mail->WordWrap = 50;
if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
}
The $message contains latin characters. Unfortunately all webmail (gmail, webmail.mydomain.org, emailaddress.domain.xx) is using a different coding.
How can I force to use UTF-8 coding to show my mail exactly the same on all mailboxes?
I tried to convert the mail header width mb_convert_encoding(), but without luck.
If you are 100% sure $message contain ISO-8859-1 you can use utf8_encode as David says. Otherwise use mb_detect_encoding and mb_convert_encoding on $message.
Also take note that
$mail -> charSet = "UTF-8";
Should be replaced by:
$mail->CharSet = "UTF-8";
And placed after the instantiation of the class (after the new). The properties are case sensitive! See the PHPMailer doc fot the list & exact spelling.
Also the default encoding of PHPMailer is 8bit which can be problematic with UTF-8 data. To fix this you can do:
$mail->Encoding = 'base64';
Take note that 'quoted-printable' would probably work too in these cases (and maybe even 'binary'). For more details you can read RFC1341 - Content-Transfer-Encoding Header Field.
$mail -> CharSet = "UTF-8";
$mail = new PHPMailer();
line $mail -> CharSet = "UTF-8"; must be after $mail = new PHPMailer();
try this
$mail = new PHPMailer();
$mail->CharSet = "UTF-8";
I work myself this way
$mail->FromName = utf8_decode($_POST['name']);
http://php.net/manual/en/function.utf8-decode.php
When non of the above works, and still mails looks like ª הודפסה ×•× ×©×œ:
$mail->addCustomHeader('Content-Type', 'text/plain;charset=utf-8');
$mail->Subject = '=?UTF-8?B?' . base64_encode($subject) . '?=';;
Sorry for being late on the party. Depending on your server configuration, You may be required to specify character strictly with lowercase letters utf-8, otherwise it will be ignored. Try this if you end up here searching for solutions and none of answers above helps:
$mail->CharSet = "UTF-8";
should be replaced with:
$mail->CharSet = "utf-8";
I was getting ó in $mail->Subject /w PHPMailer.
So for me the complete solution is:
// Your Subject with tildes. Example.
$someSubjectWithTildes = 'Subscripción España';
$mailer->CharSet = 'UTF-8';
$mailer->Encoding = 'quoted-printable';
$mailer->Subject = html_entity_decode($someSubjectWithTildes);
Hope it helps.
$mail = new PHPMailer();
$mail->CharSet = "UTF-8";
$mail->Encoding = "16bit";
The simplest way and will help you with is set CharSet to UTF-8
$mail->CharSet = "UTF-8"
To avoid problems of character encoding in sending emails using the class PHPMailer we can configure it to send it with UTF-8 character encoding using the "CharSet" parameter, as we can see in the following Php code:
$mail = new PHPMailer();
$mail->From = 'midireccion#email.com';
$mail->FromName = 'Mi nombre';
$mail->AddAddress('emaildestino#email.com');
$mail->Subject = 'Prueba';
$mail->Body = '';
$mail->IsHTML(true);
// Active condition utf-8
$mail->CharSet = 'UTF-8';
// Send mail
$mail->Send();
Related
I'm getting èé#à à à ùà characters in mail when I'm sending mail via phpmailer if I'm using simple php mail function instead of phpmailer its working fine.
code:
<?php
require 'phpmailer/PHPMailerAutoload.php';
$templatepath = $_SERVER['DOCUMENT_ROOT'].'/customer/Templates/';
$body = file_get_contents($templatepath.$template_name);
$other['--TEMPLATE_URL--'] = $templatepath;
foreach($other as $k => $v) {
$body = str_replace($k,$v,$body);
}
$body = wordwrap(trim($body), 70, "\r\n");
$body = convert_smart_quotes($body);
$mail = new PHPMailer;
$mail->SMTPDebug = 0;
$mail->Debugoutput = 'html';
$mail->Host = $email_hostname;
$mail->Username = $email_username;
$mail->Password = $email_password;
$mail->setFrom($from_email, $company_name);
$mail->addReplyTo($from_email, $company_name);
$mail->addAddress($to, '');
$mail->Subject = $subject;
$mail->msgHTML($body);
if (!$mail->send()) {
return 1;
} else {
return 0;
}
?>
I think you have to add this line :
$mail->CharSet = 'UTF-8';
May be this happen because of charset has not been set.
use it $mail->CharSet = 'utf-8' after $mail = new PHPMailer();
We have a site on godaddy server. We have a contact form. When user filled form, first we should send mail to our info#oursite, after we should send mail to user's mail from our info#oursite. My tried code below:
$name = $_POST['name'];
$email = $_POST['email'];
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 2;
$mail->port = 25;
$mail->Host = 'localhost';
$mail->Username = 'username#example.com';
$mail->Password = 'password';
$mail->addAddress($email, $name);
$mail->subject = 'Subject';
$mail->MsgHTML('mail içeriği');
if ($mail->Send()){
this outputs below:
it seems mail delivered, but it never delivered the message.
I tried many things;
$mail->SMTPAuth = true;
port 25,80,3535,465(with ssl),
tls, ssl authentication,
what should I do? what should I try more, any ideas?
First of all, you're using a very old version of PHPMailer; get the latest.
I don't know where you got your code, but you've got the case of some vital properties wrong - I suggest you base your code on the examples provided with PHPMailer. In particular, subject should be Subject and port should be Port. When sending to localhost you don't need a username or password, so you don't need to set them. Similarly, Port defaults to 25, so you don't need to set it.
You're not specifying a From address, and it looks like whatever address you're passing to addAddress is invalid, so you're sending a message from nobody to nobody - and not surprisingly it's not going anywhere!
It looks like your message body is in Turkish (?), which will not work in the default ISO-8859-1 character set, so I suggest you switch to UTF-8 by setting $mail->CharSet = 'UTF-8';.
Check your return values when calling addAddress to make sure the submitted value is valid before trying to send to it.
With these things fixed:
$name = $_POST['name'];
$email = $_POST['email'];
$mail = new PHPMailer;
if (!$mail->addAddress($email, $name)) {
die('Invalid email address');
}
$mail->isSMTP();
$mail->CharSet = 'UTF-8';
$mail->SMTPDebug = 2;
$mail->Host = 'localhost';
$mail->Subject = 'Subject';
$mail->msgHTML('mail içeriği');
$mail->setFrom('me#example.com', 'My Name');
if ($mail->send()) {
echo 'Sent';
} else {
echo 'Error: '.$mail->Errorinfo;
}
i'm trying to send an email with a japanese character with PHPmailer,
This is my function :
function sendMail()
{
mb_language('ja');
mb_internal_encoding('UTF-8');
$mail = new PHPMailer();
$mail->isSMTP();
$mail->SMTPAuth = true;
$mail->Host = EMAIL_HOST;
$mail->Port = EMAIL_PORT;
$mail->Username = EMAIL_USERNAME;
$mail->Password = EMAIL_PASSWORD;
$mail->SMTPKeepAlive = true;
$mail->Mailer = 'smtp';
$mail->CharSet = 'ISO-2022-JP';
$mail->Encoding = "7bit";
$mail->SMTPDebug = 0;
$mail->From = EMAIL_SET_FROM_EMAIL;
$mail->FromName = mb_encode_mimeheader(EMAIL_SET_FROM_NAME, "ISO-2022-JP-MS");
$mail->addAddress($this->to);
if (!empty($this->replyTo)) {
$mail->addReplyTo($this->replyTo);
}
$mail->isHTML(true);
$mail->Subject = mb_encode_mimeheader($this->subject, "ISO-2022-JP-MS");
$mail->Body = mb_convert_encoding($this->body, "ISO-2022-JP-MS", "UTF-8");
$isSend = $mail->send();
if (!$isSend) {
throw new exception(__METHOD__ . '() ' . $mail->ErrorInfo);
}
}
In the recipient the email body which have Japanese character sometimes broken like this :
Case 1 : エ %j%" : A
Case 2 : My friends Japanese laptop showing several black diamond character with question mark in it. Its on Gmail,
Case 3 : A question mark appear in some Japanese character.
Can any body show me the correct setting for PHP mailer so it can send a Japanese-character mail without unknown character shown in the recipient ?
The black diamond with the question mark on viewing browser means that it has no glyph for that character. The character may be valid but it cannot be displayed.
In other words, it may be a limitation with the system doing the display and not your program.
You should check your program, though. Open the email in a hex editor and verify that the code is what you expect and matches the encoding you've specified.
You are encoding stuff yourself, and then PHPMailer will be doing it again. When you set the subject and body, just use raw text in the correct charset, don't encode it yourself. You're also setting 7bit encoding with a charset that will not fit into 7 bits. If your text is already in UTF-8, why not stick with that? UTF-8 processing is generally more reliable than 8-bit charsets.
I m facing some character encoding issues like this:
D\\\'Huison-Longueville Référence
Original Text was :
D'Huison-Longueville Référence
Here is my PHP Mailer script:
$mail = new PHPMailer();
$mail->CharSet = 'UTF-8';
$mail->IsMail();
$mail->Subject = $subject;
$mail->IsHTML(true);
$mail->Body = $email_body;
$mail->From='support#xyz.com';
$mail->FromName= "Support Team";
$mail->AddAddress($toEmail);
$mail->Send();
I had the same problem. The charset was not being changed although I was specifying the new one like you with:
$mail->CharSet = 'UTF-8';
Since you use "IsMail" you have to go to the folder where class.phpmailer.php resides (generally in the same folder as the main phpmailer.php file) and edit it. There you will see the default values for the mail and you will see that it is set to "ISO-8859-1".
Change
public $CharSet = 'ISO-8859-1';
to
public $CharSet = 'UTF-8';
Change it to "UTF-8" or any other charset you want.
I am using PHPMailer API for sending emails. I was wondering how can I send the subject in Arabic (non-English) language
$mail->CharSet = 'utf-8';
$array= FetchTable('cos');
$subject = $_POST['subject'];
$body = $_POST['body'];
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "host";
$mail->SMTPAuth = true;
$mail->Username = "yaz#enfaltourism.com";
$mail->Password = "*******";
$mail->Port = "587";
$mail->From = "yaz#enfaltourism.com";
$mail->FromName = "Enfaltourism";
$mail->Subject = $subject;
$mail->AddAddress($email);
$mail->Send();`
The email is being successfully sent, but the problem is in sending subject in Arabic language. The email message body is displayed properly in Arabic after I set the char encoding but the the subject is being displayed in weird characters
Update
include("../mail/class.phpmailer.php");
$array= FetchTable('cos');
$subject = $_POST['subject'];
$body = $_POST['body'];
$mail = new PHPMailer();
$mail->CharSet = 'utf-8';
$mail->IsSMTP();
$mail->Host = "mail.enfaltourism.com";
$mail->SMTPAuth = true;
$mail->Username = "yaz#enfaltourism.com";
$mail->Password = "*****";
$mail->Port = "587";
$mail->From = "yaz#enfaltourism.com";
$mail->FromName = "Enfaltourism";
$mail->Subject = $subject;
i fixed as u told but the subject still weird character like this
I had this same problem with Japanese characters, both in the body and in the subject line:
I resolved it (email looks outstanding now) by doing:
$mail = new PHPMailer();
$mail->CharSet = 'UTF-8';
There really isn't any need to encode the subject separately so long as the object has the CharSet property set to UTF-8.
you can try using this code. Let me know if it helps
$phpmailer->Subject = "=?UTF-8?B?".base64_encode($subject)."?=";
Try encoding subject with base64_encode
$subject = '=?UTF-8?B?'.base64_encode('سلام علیکم').'?=';
However with setting the issue must be solved.
$mail = new PHPMailer;
$mail->CharSet = 'UTF-8';
Try this:
$mail->CharSet = 'UTF-8';
$mail->Subject = html_entity_decode("Recuperación de contraseña");
I did use this in my code and it worked!
Results