Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何从电子邮件中删除额外的非英语字符?_Php_Email_Imap - Fatal编程技术网

Php 如何从电子邮件中删除额外的非英语字符?

Php 如何从电子邮件中删除额外的非英语字符?,php,email,imap,Php,Email,Imap,我使用以下脚本阅读电子邮件 <?php //Fetch users from table $sql_users=mysql_query("select userName, realpass,userID from users "); while($row = mysql_fetch_assoc($sql_users)){ $username=$row['userName'].'@example.com'; // Email address is us

我使用以下脚本阅读电子邮件

<?php
   //Fetch users from table 
   $sql_users=mysql_query("select  userName, realpass,userID  from users ");

   while($row = mysql_fetch_assoc($sql_users)){
       $username=$row['userName'].'@example.com'; // Email address is username@domain.com 
       $password=$row['realpass'];
       $hostname = '{example.com:995/pop3/ssl/novalidate-cert}'; 
       $username = $username; $password = $password; 
       $imap = imap_open($hostname,$username,$password) or die('Cannot connect: ' . imap_last_error());

       for ($i = 1; $i <= $message_count; ++$i){
           $header = imap_header($imap, $i);
           // fetch message body and mark it as read
       $body = imap_fetchbody($imap, $i,2,FT_PEEK);
           $prettydate = date("jS F Y", $header->udate);

       if (isset($header->from[0]->personal)) {
               $personal = $header->from[0]->personal;
           } else {
               $personal = $header->from[0]->mailbox;
           }
           $subject=$header->Subject;
           //display email content   
           $email = "$personal <{$header->from[0]->mailbox}@{$header->from[0]->host}>";
           echo "On $prettydate, $email said \"$body\".\n";
           echo '<br><br>';
   }
       print_r(imap_errors());
       imap_close($imap);
}

在PHP参考资料中,有一个问题与您的问题类似。在该评论中,他这样解读内容:

 $text = trim( utf8_encode( quoted_printable_decode( 
                    imap_fetchbody( $this->inbox, $emailNo, $section ) ) ) );

尝试根据您的代码调整该示例,并尝试一下。

您有电子邮件示例吗?@Class我已将问题编辑为包含示例文本。请检查。@cartina在屏幕上显示消息时,请小心将
内容类型设置为
utf-8
字符集