utf-8 charset没有与PEAR Mail_mime联系表格

时间:2021-10-27 07:16:57

I've found and tried various solutions given in other questions about utf-encoding for special characters and other related problems, but without any success.

我已经找到并尝试了其他问题中给出的关于特殊字符和其他相关问题的utf编码的各种解决方案,但没有任何成功。

I have an html contact form that sends information to my mail address with a simple php script using PEAR Mail mime. I can send information containing special characters from my test site on localhost with no problems, but not after I uploaded to my server.

我有一个html联系表单,使用PEAR Mail mime通过简单的PHP脚本将信息发送到我的邮件地址。我可以在localhost上发送包含来自我的测试站点的特殊字符的信息,没有问题,但是在我上传到我的服务器之后没有。

eg message: Test special characters: é è ç à ô

例如消息:测试特殊字符:éèçàô

after being sent from server becomes: Test special characters: é è ç à ô

从服务器发送后变为:测试特殊字符:éÃÃÃÃÃÃÃÃ

I am guessing it's an encoding problem from my web server, but am kinda stuck at how to resolve the problem.

我猜这是我的网络服务器的编码问题,但我有点坚持如何解决问题。

The meta tags in file containing the form are set to:

包含表单的文件中的元标记设置为:

<meta charset="utf-8"> 

and the form is specified to accept charset utf-8:

并且表单被指定为接受charset utf-8:

<form name="contact" method="post" action="assets/send_form.php" accept-charset="UTF-8">

I've also tried sending content from php file with:

我也试过从php文件发送内容:

header("Content-Type: text/html; charset= UTF-8");

as well as creating $headers for the message with 'Content-Type' = 'text/html; charset="UTF-8".

以及'Content-Type'='text / html;为消息创建$标题;以及字符集= “UTF-8”。

The relevant php code in my script:

我脚本中的相关php代码:

//This section creates the email headers
$headerss=array(); 
$headerss['From']= $from_address; 
$headerss['To']= $siteEmail; 
$headerss['Subject']= $email_subject; 
$headerss['Return-Path']= $contactEmail; 
$headerss['Date']= date("r"); 
$headerss['Content-Type'] = 'text/html; charset="UTF-8"';  

// This section creates the smtp inputs
$auth = array('host' => $host, 'port' => $port, 'auth' => true, 'username' => $username, 'password' => $password);

// create new Mail_mime instance, set utf-8 charset
$mail = new Mail_mime();
$mail -> setHTMLBody($email_message); 


//CHECK THIS OUT FOR UTF-8 ***************************** 

$mimeparams=array(); 
$mimeparams['text_encoding']="7bit"; 
$mimeparams['text_charset']="UTF-8"; 
$mimeparams['html_charset']="UTF-8";
$mimeparams['head_charset']="UTF-8"; 
$mimeparams['eol']= "\n" ; 

$body = $mail->get($mimeparams); 
$headers = $mail->headers($headerss); 


// This section send the email
$smtp = Mail::factory('smtp', $auth);
$sendmail = $smtp->send($siteEmail, $headers, $body);

Any help will be really appreciated. Thanks.

任何帮助将非常感激。谢谢。

2 个解决方案

#1


0  

Try to put before

试着把它放在前面

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

#2


0  

I experienced the same problem and my solution was to save the php file in same format, in UTF-8 as I had saved in ANSI format. That solved my problem anyway.

我遇到了同样的问题,我的解决方案是以相同的格式保存php文件,以UTF-8格式保存。无论如何,这解决了我的问题。

#1


0  

Try to put before

试着把它放在前面

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

#2


0  

I experienced the same problem and my solution was to save the php file in same format, in UTF-8 as I had saved in ANSI format. That solved my problem anyway.

我遇到了同样的问题,我的解决方案是以相同的格式保存php文件,以UTF-8格式保存。无论如何,这解决了我的问题。