phpmailer类从数据库发送无效字符

时间:2014-10-27 18:36:03

标签: php mysql utf-8 mysqli phpmailer

我使用PHPMailer Class发送电子邮件,如下所示:

$mail = new PHPMailer;
        $mail->CharSet = 'UTF-8';
        $mail->isSMTP();                                      // Set mailer to use SMTP
        $mail->Host = _MAIL_SMTP_HOST_;                       // Specify main and backup server
        $mail->SMTPAuth = true;                               // Enable SMTP authentication
        $mail->Username = _MAIL_SMTP_USER_;                   // SMTP username
        $mail->Password = _MAIL_SMTP_PASS_;               // SMTP password
        $mail->SMTPSecure = 'tls';                            // Enable encryption, 'ssl' also accepted
        $mail->Port = _MAIL_SMTP_PORT_;                                    //Set the SMTP port number - 587 for authenticated TLS
        $mail->setFrom(_MAIL_SMTP_FROM_, _MAIL_SMTP_FROM_NAME_);     //Set who the message is to be sent from
        $mail->addAddress(_MAIL_SMTP_TO_, _MAIL_SMTP_TO_NAME_); 
        $mail->addAddress($to);     // Add a recipient
        $mail->WordWrap = 50;
        $mail->isHTML(true);     
        $mail->addAttachment($file);        // Set email format to HTML
        $mail->Subject = $subject;
        $mail->Body    = $body;
        $mail->AltBody = $altbody;
        if(!$mail->send()) {
        echo 'Message could not be sent.';
        echo 'Mailer Error: ' . $mail->ErrorInfo;
        exit;
        }

我从我的数据库发送正文消息但在电子邮件中我看到了这个输出:

????????

PHPMailer如何使用utf-8个字符?

注意:我有这个用于mysql:mysql_query("SET NAMES utf8");和MySqli:$mysqli->set_charset("utf8")我同时检查(mysql和mysqli)

0 个答案:

没有答案