我正在尝试编写一个 php 电子邮件转发脚本。我为此编写了一个简单的代码,从 imap 读取电子邮件并将它们发送到特定的电子邮件地址。
但问题是它不工作:) 它发送没有电子邮件正文的电子邮件。
/* connect to imap */
$hostname = '{mail.myserver.com:143/notls}INBOX';
$username = 'email@myserver.com';
$password = 'password';
/* try to connect */
$inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error());
/* grab emails */
$emails = imap_search($inbox,'ALL');
/* if emails are returned, cycle through each... */
if($emails)
{
/* put the newest emails on top */
rsort($emails);
/* for every email... */
foreach($emails as $email_number) {
/* get information specific to this email */
$overview = imap_fetch_overview($inbox,$email_number,0);
$message = imap_fetchbody($inbox,$email_number,2);
$full = imap_fetchheader($inbox, $email_number);
$body = imap_body($inbox, $email_number);
imap_mail("targetaddress@hotmail.com","title", $body,$full);
break;
}
}
/* close the connection */
imap_close($inbox);