11
我試圖用PHPmailer類發送電子郵件,但是我發送的html爲空,或者字符未配置,且沒有重音。不能用PHPMailer發送帶有正確字符的電子郵件
<?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('[email protected]', 'Conectfarma');
$mail->AddReplyTo('[email protected]', '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配置,因爲它的工作正常。
確保你的代碼是UTF8,取消註釋'$ mail-> CharSet =「UTF-8」;'。不要用你的母語編寫代碼。 –
@TomaszKowalczyk剛剛評論說,但即使如此,我收到的電子郵件是「N o o vaimaâà」。對於母語感到抱歉。 – darkman
你真的確定你的文件是UTF-8編碼嗎? –