我正在构建一个电子邮件阅读脚本,它通过imap阅读电子邮件,当我尝试使用imap_fetchbody阅读电子邮件正文时它只显示文本,但是电子邮件正文有一个链接似乎没有显示,
这是我的代码
$hostname = '{mail.test.com/notls}INBox';
$username = 'info@test.com';
$password = 'testopw';
/* try to connect */
$inBox = imap_open($hostname,$username,$password) or die('Cannot connect to Email Server: ' . imap_last_error());
/* grab emails */
$emails = imap_search($inBox,'SEEN FROM "noreply@test.com"');
if($emails) {
/* put the newest emails on top */
rsort($emails);
/* for every email... */
foreach($emails as $email_number) {
/* get information specific to this email */
echo $message = imap_fetchbody($inBox,$email_number,1);
}
}
We do our utmost to arrive to you on time. There may, however,
be unexpected circumstances, causing our driver to be delayed.
You can follow the current status of your assignment here.
当我从邮件客户端文本中读取电子邮件时,这里有一个链接,但是当读取使用PHP时它只显示一个文本,
电子邮件屏幕截图
有人知道这个问题的原因是什么,或者是否需要更改一些参数以获取与url的链接.谢谢
解决方法:
您必须检查电子邮件的多个部分.您实际上可以阅读电子邮件的源代码.它很容易理解,您将识别不同的部分.
imap_fetchbody($inBox,$email_number,$section);
http://php.net/manual/en/function.imap-fetchbody.php
(empty) - Entire message
0 - Message header
1 - MULTIPART/ALTERNATIVE
1.1 - TEXT/PLAIN
1.2 - TEXT/HTML
2 - file.ext
您在评论中提到的部分是PNG文件.某些部分可以在base64中编码为电子邮件,它是基于文本的协议.
电子邮件示例:
From: Nathaniel Borenstein <nsb@bellcore.com>
To: Ned Freed <ned@innosoft.com>
Subject: Sample message
MIME-Version: 1.0
Content-type: multipart/mixed; boundary="simple
boundary"
This is the preamble. It is to be ignored, though it
is a handy place for mail composers to include an
explanatory note to non-MIME compliant readers.
--simple boundary
This is implicitly typed plain ASCII text.
It does NOT end with a linebreak.
--simple boundary
Content-type: text/plain; charset=us-ascii
This is explicitly typed plain ASCII text.
It DOES end with a linebreak.
--simple boundary--
This is the epilogue. It is also to be ignored.
https://www.w3.org/Protocols/rfc1341/7_2_Multipart.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。