[英]PHP Mailer UTF-8 Encoding problems
我最近一直在開發一個網站,並決定在其中包含一個 PHPMailer。 問題是我是匈牙利人,而且該網站也完全是匈牙利語,所以我不得不使用 UTF-8 字符集。 我決定使用的 PHP 郵件程序尚不能使用 UTF-8,我無法弄清楚如何使其在我喜歡的字符集中回顯內容。 請幫忙!
<?php
require_once('phpmailer/class.phpmailer.php');
$mail = new PHPMailer();
if( isset( $_POST['template-contactform-submit'] ) AND $_POST['template-contactform-submit'] == 'submit' ) {
if( $_POST['template-contactform-name'] != '' AND $_POST['template-contactform-email'] != '' AND $_POST['template-contactform-message'] != '' ) {
$name = $_POST['template-contactform-name'];
$email = $_POST['template-contactform-email'];
$phone = $_POST['template-contactform-phone'];
$service = $_POST['template-contactform-service'];
$subject = $_POST['template-contactform-subject'];
$message = $_POST['template-contactform-message'];
$subject = isset($subject) ? $subject : 'New Message From Contact Form';
$botcheck = $_POST['template-contactform-botcheck'];
$toemail = ''; // Your Email Address
$toname = ''; // Your Name
if( $botcheck == '' ) {
$mail->SetFrom( $email , $name );
$mail->AddReplyTo( $email , $name );
$mail->AddAddress( $toemail , $toname );
$mail->Subject = $subject;
$name = isset($name) ? "Név: $name<br>" : '';
$email = isset($email) ? "E-mail: $email<br><br>" : '';
$message = isset($message) ? "Üzenet: $message<br>" : '';
$referrer = $_SERVER['HTTP_REFERER'] ? '<br><br><br>Az üzenetet továbbította: ' . $_SERVER['HTTP_REFERER'] :'';
$body = "$name $email $message $referrer";
$mail->MsgHTML( $body );
$mail->CharSet="UTF-8";
$sendEmail = $mail->Send();
if( $sendEmail == true ):
echo 'Üzenet elküldve!';
else:
echo 'Üzenetküldés sikertelen. Kérlek próbáld újra!' . $mail->ErrorInfo . '';
endif;
} else {
echo 'Bot vagy. Kérlek próbálkozz újra!';
}
} else {
echo 'Kérlek tölts ki minden mezőt és próbáld meg újra!';
}
} else {
echo 'Valami félrecsúszott. Kérlek próbáld meg mégegyszer.';
}
?>
嘗試更換:
$mail->CharSet="UTF-8";
經過:
$mail->CharSet = 'UTF-8';
它在這里工作得很好。
有用的是在發送內容之前通過 utf8_decode() php 函數解碼內容。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.