Created
May 15, 2018 19:56
-
-
Save seppenen/163a05b2250f884ff1e762f6da3c7cef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if($_GET['action'] == "get") { | |
$hostname = '{imap.gmail.com:993/imap/ssl}INBOX'; | |
$username = '[email protected]'; | |
$password = ''; | |
$inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error()); | |
$emails = imap_search($inbox,'FROM "[email protected]" UNSEEN'); | |
if($emails) { | |
$output = ''; | |
rsort($emails); | |
foreach($emails as $email_number) { | |
$overview = imap_fetch_overview($inbox,$email_number,0); | |
$structure = imap_fetchstructure($inbox, $email_number); | |
if(isset($structure->parts) && is_array($structure->parts) && isset($structure->parts[1])) { | |
$part = $structure->parts[1]; | |
$message = imap_fetchbody($inbox,$email_number,2); | |
if($part->encoding == 3) { | |
$message = imap_base64($message); | |
} else if($part->encoding == 1) { | |
$message = imap_8bit($message); | |
} else { | |
$message = imap_qprint($message); | |
} | |
} | |
$output.= '<div class="body">'.utf8_decode(imap_utf8($message)).'</div><hr />'; | |
} | |
imap_close($inbox); | |
$pos = strpos($output, 'Please advise acceptance of this booking by clicking on the GREEN'); | |
if ($pos === false) { | |
}else { | |
preg_match_all('#\bhttps?://[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/))#', $output, $match); | |
$link= $match[0]['1']; | |
echo $link; | |
} | |
} | |
} | |
?> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment