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
字符集