我构建了一个小脚本来在Joomla网站上运行电子邮件发送的端到端测试:
$testMailer =& JFactory::getMailer();
$testMailer->setSender(SENDER);
$testMailer->addReplyTo(SENDER);
$testMailer->addRecipient(TEST_EMAIL);
$subject = 'Automatic test '.md5(uniqid());
$testMailer->setSubject($subject);
$testMailer->setBody('This message is automatically retrieved. Please ignore.');
?>
<h2>Testing Joomla email sending functionality</h2><?php
flush();
if ($testMailer->Send() !== true) {
echo '<p>ERROR - Mail Sending failed</p>';
}else{
echo '<p>Email sent...</p>';
flush();
$sleep = 5;
$progress = 0;
$max = 300;
set_time_limit($max+30);
$found = 0;
$mbox = imap_open(TEST_IMAP_SERVER, TEST_EMAIL, TEST_PASSWORD);
if (!$mbox){
echo '<p>ERROR - Login to '.TEST_EMAIL.' failed</p>';
foreach (imap_errors() as $error){
echo '<p>'.$error.'</p>';
}
die();
}else{
while (!$found && $progress < $max){
$result = imap_search($mbox, 'SUBJECT "'.$subject.'"');
foreach($result as $msgno) {
$headers = imap_fetchheader($mbox, $msgno);
if ($headers){
echo '<p>OK - EMail received</p>';
imap_delete($mbox,$msgno);
$found = 1;
die();
}
}
}
if (!$found){
$progress+=$sleep;
echo '<p>Waiting '.$sleep.' seconds to try again...('.$progress.' seconds total wait)</p>';
flush();
sleep($sleep);
}
}
if (!$found){
echo '<p>ERROR Giving up after '.$max.' seconds</p>';
}
}
这个脚本在我的loal开发机器上工作正常,并且始终发现消息已发送。
实时网站位于Amazon EC2服务器上。起初,我收到了异常登录活动的警告。我确认脚本已知,并在10分钟内重新开始。
从那时起,脚本可以登录,但imap_search永远不会找到任何消息。然而,它们会到达收件箱。开发站点上的脚本仍然正常。
亚马逊服务器上的Telnet也正常运行
telnet imap.gmail.com 993
Trying 74.125.133.108...
Connected to gmail-imap.l.google.com.
Escape character is '^]'.
有什么想法吗?