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