不能使用PHPMailer发送具有正确字符的电子邮件 [英] Cant send email with correct characters with PHPMailer

查看:114
本文介绍了不能使用PHPMailer发送具有正确字符的电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用PHPmailer类发送电子邮件,但是我发送的html是空的,或者字符是未配置的,没有重音。

I'm trying to send a e-mail with the PHPmailer class, but the html i send, is empty, or the characters are unconfigured, and without accents.

<?php
header("Content-Type: text/html; charset=ISO-8859-1", true);
require_once('class.phpmailer.php');
include "config.php";

$nome = trim($_POST['nome']);
$email  = trim($_POST['Imail']);
$usuario = trim($_POST['usuario']);
$senha = trim($_POST['senha']);
$mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch

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

try {
  $mail->AddAddress($email, $nome);
  $mail->SetFrom('editora@conectfarma.net', 'Conectfarma');
  $mail->AddReplyTo('editora@conectfarma.net', 'Conectarma');
  $subject = 'Guia Rápido de Interações Medicamentosas';
  $sendsubject= "=?utf-8?b?".base64_encode($subject)."?=";
  $mail->Subject = $sendsubject;
 $mensagem  = "<!DOCTYPE html>
<html>
<body>
Bem vindo ao Guia Rápido de Interações Medicamentosas em Neurologia e Psiquiatria
Seu Login e Senha para acesso ao aplicativo são:\n
Login:"  .$nome. "\n, Senha : " .$senha.
"\nAtenciosamente,
Conectfarma Publicações Científicas
</body>
</html>";

  $mail->Body = $mensagem;
  //$mail->CreateBody($mensagem);
  $mail->IsHTML(true);
  $mail->Send();
  //$mail->CharSet="UTF-8";
  echo "<!DOCTYPE html>
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>
<title>Confirmação</title>
</head>
<body>
Não vai maçã.
</body>
</html>
";
} catch (phpmailerException $e) {
  echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
  echo $e->getMessage(); //Boring error messages from anything else!
}
        }
    }
}

?>

我跳过了SMTP配置,因为它的工作正常。

I jumped the SMTP configuration because its working properly.

推荐答案

双重检查您的PHP代码也是UTF-8编码。

Double check Your PHP code is also in UTF-8 encoding.

取消注释行 // $ mail-> CharSet =UTF-8; 并在 $ mail = new PHPMailer(true); ,所以代码看起来像:

Uncomment the line //$mail->CharSet="UTF-8"; and move it idealy right after the $mail = new PHPMailer(true);, so the code would look like:

// ...
$mail = new PHPMailer(true);
$mail->CharSet = "UTF-8";
// ...

在你的代码中,它是在$ code> $ mail-> Send(); 因此,字符集设置不会计入...

In Your code it is called after the $mail->Send(); thus the charset setting did not take in count...

这篇关于不能使用PHPMailer发送具有正确字符的电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆