【发布时间】:2018-07-23 02:47:51
【问题描述】:
如果其中包含某个单词,我想取消设置数组值。我正在做的是,我从 gmail 收件箱中提取所有电子邮件,并且只显示来自消息正文的电子邮件,以便我可以在数据库中更新它。邮件正文包含很少的电子邮件,因为它用于未送达的电子邮件。
当所有的电子邮件都显示出来时,它还会显示我不想要的电子邮件是从哪里发送的。
代码如下:
/*=================================== GMAIL ======================================*/
/* connect to gmail */
//$hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
$username = 'username@gmail.com';
$password = 'password';
//$inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error());
//Which folders or label do you want to access? - Example: INBOX, All Mail, Trash, labelname
//Note: It is case sensitive
$imapmainbox = "INBOX";
//Select messagestatus as ALL or UNSEEN which is the unread email
$messagestatus = "ALL";
//-------------------------------------------------------------------
//Gmail Connection String
$imapaddress = "{imap.gmail.com:993/imap/ssl}";
//Gmail host with folder
$hostname = $imapaddress . $imapmainbox;
//Open the connection
$connection = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error());
//Grab all the emails inside the inbox
$emails = imap_search($connection,$messagestatus);
//number of emails in the inbox
$totalemails = imap_num_msg($connection);
echo "Total Emails: " . $totalemails . "<br>";
if($emails) {
//sort emails by newest first
rsort($emails);
//loop through every email int he inbox
foreach($emails as $email_number) {
//grab the overview and message
$header = imap_fetch_overview($connection,$email_number,0);
//Because attachments can be problematic this logic will default to skipping the attachments
$message = imap_fetchbody($connection,$email_number,1.1);
if ($message == "") { // no attachments is the usual cause of this
$message = imap_fetchbody($connection, $email_number, 1);
}
//split the header array into variables
$status = ($header[0]->seen ? 'read' : 'unread');
$subject = $header[0]->subject;
$from = $header[0]->from;
$date = $header[0]->date;
preg_match_all("/[\._a-zA-Z0-9-]+@[\._a-zA-Z0-9-]+/i", $message, $matches);
//$matches = array_unique($matches);
// remove some of the emails which i dont want to include
$matches[0] = remove(remove(remove(array_unique($matches[0]) , 'info@example.co.uk') , 'no-reply@example.co.uk'), '131669395@infong353.kundenserver.de') ;
foreach($matches[0] as $email) {
//echo $email . "<br>";
echo '
<div class="alert alert-primary" role="alert">
'.$email.' in <b>'.category_name(cat_id_from_email($email)).'</b> group <br><br>
<a href="index.php?p=gmail&undelivered='.$email.'" class="btn btn-info nounderline" >Undelivered</a>
<a href="index.php?p=gmail&unsubscribers='.$email.'" class="btn btn-warning nounderline" >Unsubscribers</a>
<a href="index.php?p=gmail&delete='.$email.'" class="btn btn-danger nounderline" >Delete</a>
</div>
';
}
}
}
// close the connection
imap_close($connection);
我还想删除任何具有特定域名的电子邮件地址。例如:
如果任何电子邮件是 xxxxx@example2.com,我想取消设置。所以基本上任何带有 example2.com 的电子邮件地址。
谁能帮帮我。
【问题讨论】:
-
我们总是乐于帮助和支持新的编码员,但您需要先帮助自己。 :-) 在doing more research 之后,如果您有问题发布您尝试过的方法,并清楚地解释什么不起作用并提供a Minimal, Complete, and Verifiable example。阅读How to Ask 一个好问题。请务必take the tour 并阅读this。
-
你能给我一个完全相同的问题的链接吗?我找不到任何可以帮助我的东西
-
不是问题,是副本中链接的答案。查看页面顶部。
-
没人知道
remove()是什么,但是看看php.net/manual/en/function.preg-grep.php 和PREG_GREP_INVERT。 -
@JayBlanchard:抱歉,我没有看到
unset($matches['some magically derived index']);有帮助或重复。