【问题标题】:How to remove extra non-english characters from email message?如何从电子邮件中删除多余的非英文字符?
【发布时间】:2013-03-22 07:11:04
【问题描述】:

我正在使用以下脚本来阅读电子邮件。

<?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);
}

问题是电子邮件返回的多余字符需要删除。我还需要将电子邮件标记为已读。 这是一个示例消息:

" 2013 年 3 月 20 日,乔说“电子邮件祈祷内容。

此 =A0 是 example.com 的测试电子邮件。它应该被转换成 一个新的祈祷请求。

谢谢,乔“。”

【问题讨论】:

  • 您有电子邮件样本吗?
  • @Class 我已编辑问题以包含示例文本。请检查。

标签: php email imap


【解决方案1】:

在 PHP 参考中,有一个 comment 与您的问题类似。在该评论中,他以这种方式阅读内容:

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

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

【讨论】:

  • @cartina 注意,当您在屏幕上显示消息时,将content-type 设置为utf-8 字符集
猜你喜欢
  • 2021-10-31
  • 1970-01-01
  • 2022-12-18
  • 2016-09-26
  • 2019-03-01
  • 2011-04-08
  • 1970-01-01
  • 1970-01-01
  • 2020-06-04
相关资源
最近更新 更多