2012-12-19 13 views
11

Próbuję wysłać wiadomość e-mail z klasą PHPmailer, ale wiadomość html wysyłam, jest pusta lub znaki są nieskonfigurowane i bez akcentów.Nie mogę wysyłać wiadomości e-mail z poprawnymi znakami za pomocą PHPMailera

<?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! 
} 
     } 
    } 
} 

?> 

Podskoczyłem konfiguracji SMTP, ponieważ działa poprawnie.

+1

Upewnij się, że kod jest UTF8, odkomentuj "$ mail-> CharSet =" UTF-8 ";'. Nie pisz kodu w swoim ojczystym języku. –

+0

@TomaszKowalczyk tylko to skomentował, ale e-mail, który otrzymuję to "Nà £ v vai maçà £.". i przepraszam za język ojczysty. – darkman

+0

Czy jesteś naprawdę pewien, że twoje pliki są kodowane w UTF-8? –

Odpowiedz

32

Podwójne sprawdzenie Twój kod PHP jest również w kodowaniu UTF-8.

Odkomentuj linia //$mail->CharSet="UTF-8"; i przenieść go idealy tuż po $mail = new PHPMailer(true);, więc kod wyglądałby następująco:

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

w kodzie jest wywoływana po $mail->Send(); zatem ustawienie charset nie podjąć w count. ..

Powiązane problemy