-
-
Notifications
You must be signed in to change notification settings - Fork 182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
imap_open(): Couldn't open stream {imap.gmail.com:993/imap} #67
Comments
Hi @elysiumtiles , If you havn't completed step 1 please do so and try again. If you completed step one and still can't connect, please try using encryption Hope it helps :) |
Thanks for the help Webklex! Below is a working copy of what worked for me. You have to set your Gmail email and password for the example to work. Thanks again OK to close this issue. This is the handle function of my command public function handle() {
/*
Laravel 5.2 .env settings
IMAP_HOST=imap.gmail.com
IMAP_PORT=993
IMAP_ENCRYPTION=ssl
IMAP_VALIDATE_CERT=true
IMAP_USERNAME=yourEmailAddress@gmail.com
IMAP_PASSWORD=yourEmailAddressPassword
IMAP_DEFAULT_ACCOUNT=default
IMAP_PROCESSED_FOLDER=FaxPoProcessed // this is the folder you want to move email to
*/
$oClient = new Client([
'host' => env('IMAP_HOST'),
'port' => env('IMAP_PORT'),
'encryption' => env('IMAP_ENCRYPTION'),
'validate_cert' => env('IMAP_VALIDATE_CERT'),
'username' => env('IMAP_USERNAME'),
'password' => env('IMAP_PASSWORD'),
]);
// select account
$oClient = Client::account(env('IMAP_DEFAULT_ACCOUNT'));
//Connect to the IMAP Server
$oClient->connect();
//Get all Mailboxes
/** @var \Webklex\IMAP\Support\FolderCollection $aFolder */
$aFolder = $oClient->getFolders();
//Loop through every Mailbox
/** @var \Webklex\IMAP\Folder $oFolder */
foreach($aFolder as $oFolder){
//Get all Messages of the current Mailbox
/** @var \Webklex\IMAP\Support\MessageCollection $oMessage */
// added this if statment only want to get the INBOX
if($oFolder->name == 'INBOX') {
// $aMessage = $oMailbox->getMessages(); original example had undefined variable
// $oMailBox changed to $oFolder
$aMessage = $oFolder->getMessages();
/** @var \Webklex\IMAP\Message $oMessage */
foreach ($aMessage as $oMessage) {
echo $oMessage->subject . '<br />';
echo 'Attachments: ' . $oMessage->getAttachments()->count() . '<br />';
echo $oMessage->getHTMLBody(true);
//Move the current Message to 'INBOX.read' // this did not work for me
// if($oMessage->moveToFolder('INBOX.read') == true){
if ($oMessage->moveToFolder(env('IMAP_PROCESSED_FOLDER')) == true) {
echo 'Message has been moved';
} else {
echo 'Message could not be moved';
}
}
}
}
} |
Hi @elysiumtiles , I would just recommend a few changes wich might save you a few lines of code. Since you already placed all required $oClient = \Client::connect(); ..or if you like to connect to another account you could use: $oClient = Client::account('other-account');
$oClient->connect(); You could also try using $oFolder = $oClient->getFolder('INBOX'); ..and each() to loop through your messages: $processed_folder = env('IMAP_PROCESSED_FOLDER');
$oFolder->getMessages()->each(function($oMessage) use($processed_folder){
/** @var \Webklex\IMAP\Message $oMessage */
echo $oMessage->subject . '<br />';
}); I also noticed your comment:
If you want to move a message into another folder, make sure it exists and your delimiter is correct. Its not always a "." it could also be a "/" or (almost) anything else... Best regards |
I'm using the same code as in #67 (comment), but I get the following error (IMAP is enabled in Gmail settings):
|
Problem solved Allow Unknown device at https://myaccount.google.com/u/1/device-activity |
Hi, i am using this details but i have not seen any device in Device activity tab |
ask your hosting provider to open 993 port |
Not working for me. Getting this error imap_open(): Couldn't open stream {{imap.gmail.com:993/imap/ssl}INBOX:993/imap/novalidate-cert/ssl}. No such host as {imap.gmail.com |
Hi @sanjay-aviox , |
Okay thanks. Webklex/php-imap package is working fine but Laravel package not working |
Laravel 5.2
I have a command that fetches email I get the error imap_open(): Couldn't open stream
$oClient->connect(); returns this error:
I appreciate any help, thanks.
The text was updated successfully, but these errors were encountered: