gpt4 book ai didi

php - 通知 : Undefined property: stdClass: error

转载 作者:可可西里 更新时间:2023-11-01 12:29:14 24 4
gpt4 key购买 nike

我正在尝试获取电子邮件正文并根据它向学习者发送回复。但是在执行我的代码时出现错误 Notice: Undefined property: stdClass::$subject 。我真的很迷茫不知道该怎么办。我在下面发布代码。

<?php 

$server = '{imap.aaa.com:993/imap/ssl}INBOX';
$username = 'aaa@bbb.com';
$password = 'aaaaaa';
require_once '../swift/lib/swift_required.php';

$connection = imap_open($server,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error());

$result = imap_search($connection,'ALL');
if($result) {


$output = '';


rsort($result);


foreach($result as $email_number) {

$overview = imap_fetch_overview($connection,$email_number,0);
$message = imap_fetchbody($connection,$email_number,2);

$output.= '<div class="toggler '.($overview[0]->seen ? 'read' : 'unread').'">';
$output.= '<span class="subject">'.$overview[0]->subject.'</span> ';
$output.= '<span class="from">'.$overview[0]->from.'</span>';
$output.= '<span class="date">on '.$overview[0]->date.'</span>';
$output.= '</div>';

$output.= '<div class="body">'.$message.'</div>';

if ($message == signup)

{

$transport = Swift_MailTransport::newInstance();
$mailer = Swift_Mailer::newInstance($transport);

$message1 = Swift_Message::newInstance('new message')
->setFrom(array('aaa@aaa.com' => 'name'))
->setTo(array('bbb@aaa.com'))
->setBody($message);


$mail = $mailer->send($message1);
}

}
}

else
{
echo "false return";
}
?>

最佳答案

来自 imap_fetch_overview 的文档:

Returns an array of objects describing one message header each. The object will only define a property if it exists.

So check if the property is set first:

if (isset($overview[0]->subject))
{
$output.= '<span class="subject">'.$overview[0]->subject.'</span> ';
}

关于php - 通知 : Undefined property: stdClass: error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12830704/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com