PHP Mailer中外语字符的主题。

时间:2014-05-09 12:56:46

标签: php character phpmailer

我面临使用新的PHPMailer()发送电子邮件的问题 我想发送ĂĂÃŢŢÎŞŞâăãţţîşş字符作为主题名称或从名称,但它不起作用...

function SendFormattedEmailContact2( $to, $name='', $subject, $msg, $From, $FromEmail, $BCC_email='')
{

    $sendDate = date("l j, F Y");
    $sendDate = str_replace(
        array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'),
        array('Ianuarie', 'Februarie', 'Martie', 'Aprilie', 'Mai', 'Iunie', 'Iulie', 'August', 'Septembrie', 'Octombrie', 'Noiembrie', 'Decembrie'),
        $sendDate
    );
    $sendDate = str_replace(
        array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'),
        array('Duminica', 'luni', 'marți', 'miercuri', 'joi', 'Vineri', 'Sâmbătă'),
        $sendDate
    );

    $msg=str_replace("##date##",date("l jS \of F Y"),$msg);

    $mailMsg = $msg;
    $mail = new PHPMailer();
    $mail->IsMail();
    //$mail->Host="mail.us.hypervibe.com";
    $mail->IsHTML(true);
    $mail->CharSet = 'ISO-8859-2';
    $mail->AddAddress($to);

    if($BCC_email != '')
        $mail->AddBCC($BCC_email);

    $mail->AddReplyTo($FromEmail);
    // $mail->Subject = "=?ISO-8859-2?B?".base64_encode($subject)."?=";
    $mail->Subject = mb_convert_encoding($subject, "ISO-8859-2", "auto");;

    $mail->Body = $mailMsg;
    $mail->From = $FromEmail;
    //$mail->FromName = "=?ISO-8859-2?B?".base64_encode($From)."?=";
    $mail->FromName = "=?ISO-8859-2?B?".base64_encode($From)."?=";
    $mail->AltBody = $mailMsg;
    $mail->Encoding = "7bit";
    return $mail->Send();
}

1 个答案:

答案 0 :(得分:0)

$mail->CharSet = 'UTF-8';
$mail->Subject = 'âăãțţîșş';

这对我有用