csa*_*as1 1 php email phpmailer
我在我的网站联系表格中使用 php mailer。当我收到希腊语的消息时,我没有收到联系表中输入的文本。在 class.phpmailer.php 文件第 59 行中,编码 public $CharSet = 'iso-8859-1';是 有没有办法使我的文本正确显示为联系表单中键入的内容?
可以在此处找到 ISO/IEC 8859-1 共同支持的语言
我也试过德语和阿尔巴尼亚语,但我也有同样的问题。我只能收到英语,如果用户在某些单词上输入另一种语言,我会收到“中文”。
编码:
<?php
require_once('phpmailer/class.phpmailer.php');
// if(isset($_POST['g-recaptcha-response'])){
if (empty($_POST['Email'])) {
$_POST['Email'] = "-";
}
if (empty($_POST['Name'])) {
$_POST['Name'] = "-";
}
if (empty($_POST['Subject'])) {
$_POST['Subject'] = " ";
}
if (empty($_POST['message'])) {
$_POST['message'] = "-";
}
$mymail = smtpmailer("example@gmail.com", $_POST['Email'], $_POST['Name'],
$_POST['Subject'], $_POST['message']);
function smtpmailer($to, $from, $from_name, $subject, $body)
{
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Debugoutput = 'html';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = 'example@gmail.com';
$mail->Password = 'pass';
$mail->SetFrom($from, $from_name);
$mail->Subject = " Contact form ~Name: $from_name ~ subject: $subject ";
$mail->Body = " You have received a new message
from $from_name, here are the details:\n\n_____
___________________\n" . "\nDear $from_name,\n
Your enquiry had been received on " . date("D j F ") . "
\nINFORMATION SUBMITTED: " . "\n\nName: $from_name\n\nEmail: $from
\nSubject: $subject\n\nMessage: $body \n\nTo:
$to\nDate: " . date("d/m/y") . "\nWebsite: " . "\n____________
__________________"; //end body
$mail->AddAddress($to);
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Well done $from_name, your message has been sent!\n
We will reply to the following email: $from" . "\nYour Message: $body";
}
} //end function smtpmailer
//}
?>
Run Code Online (Sandbox Code Playgroud)
在您的示例输出中,字符计数放大表明您正在以 UTF-8 格式从表单接收数据,但随后告诉 PHPMailer(默认情况下)它是 ISO-8859-1,这会导致您的损坏类型重见。
您应该到处使用 UTF-8。在 PHPMailer 中,您可以这样做:
$mail->CharSet = 'UTF-8';
Run Code Online (Sandbox Code Playgroud)
然后,您需要确保处理的每个步骤也支持 UTF-8。