gpt4 book ai didi

PHP Mailer UTF-8 编码问题

转载 作者:行者123 更新时间:2023-12-04 00:21:49 24 4
gpt4 key购买 nike

我最近一直在开发一个网站,并决定在其中包含一个 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';

它在这里工作得很好。

关于PHP Mailer UTF-8 编码问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31560624/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com