I'm using PHP 7.4.15 and Gmail IMAP to fetch emails from server.
Same credentials work on QA env but failing on my local machine, I'm using the following code:
$username = 'testing+some_email_queue#example.com';
$password = '<some password>';
$imap = imap_open('{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX', $username, $password);
var_dump($imap);
I'm running my code example using the following command: php -f imap.php and output is:
PHP Warning: imap_open(): Couldn't open stream {imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX in C:\Projects\<path>\imap.php on line 9
Warning: imap_open(): Couldn't open stream {imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX in C:\Projects\<path>\imap.php on line 9
bool(false)
PHP Notice: Unknown: [AUTHENTICATIONFAILED] Invalid credentials (Failure) (errflg=1) in Unknown on line 0
Notice: Unknown: [AUTHENTICATIONFAILED] Invalid credentials (Failure) (errflg=1) in Unknown on line 0
PHP Notice: Unknown: [AUTHENTICATIONFAILED] Invalid credentials (Failure) (errflg=1) in Unknown on line 0
Notice: Unknown: [AUTHENTICATIONFAILED] Invalid credentials (Failure) (errflg=1) in Unknown on line 0
PHP Notice: Unknown: [AUTHENTICATIONFAILED] Invalid credentials (Failure) (errflg=1) in Unknown on line 0
Notice: Unknown: [AUTHENTICATIONFAILED] Invalid credentials (Failure) (errflg=1) in Unknown on line 0
PHP Notice: Unknown: Too many login failures (errflg=2) in Unknown on line 0
Notice: Unknown: Too many login failures (errflg=2) in Unknown on line 0
In my php.ini file imap extension is enabled.
Any idea what might be the reason?
My code is working fine when run on windows laptop with XAMPP, but when I try to run same code on linux machine it is giving error.
My code:
<?php
$connect_to = '{imap.gmail.com:993/imap/ssl}INBOX';
$user = 'my gmail address';
$password = 'my gmail password';
$connection = imap_open($connect_to, $user, $password)
or die("Can't connect to '$connect_to': " . imap_last_error());
imap_close($connection);
?>
Error I am getting:
PHP Warning:imap_open(): Couldn't open stream {imap.gmail.com:993/imap/ssl}INBOX in /home/re-work/test_imap.php on line 30
Array
(
[type] => 2
[message] => imap_open(): Couldn't open stream {imap.gmail.com:993/imap/ssl}INBOX
[file] => /home/re-work/test_imap.php
[line] => 30
)
PHP Warning: imap_num_msg() expects parameter 1 to be resource, boolean given in /home/re-work/test_imap.php on line 39
PHP Warning: imap_search() expects parameter 1 to be resource, boolean given in /home/re-work/test_imap.php on line 42
0</br>PHP Notice: Unknown: Retrying PLAIN authentication after [ALERT] Please log in via your web browser: https://support.google.com/mail/acco (errflg=1) in Unknown on line 0
PHP Notice: Unknown: Retrying PLAIN authentication after [ALERT] Please log in via your web browser: https://support.google.com/mail/acco (errflg=1) in Unknown on line 0
PHP Notice: Unknown: Can not authenticate to IMAP server: [ALERT] Please log in via your web browser: https://support.google.com/mail/acco (errflg=2) in Unknown on line 0
Please help where and what I am missing?
Basically, my code should work because it works when I run the website locally. Though, when I upload it to the dedicated server, it will show these errors:
Notice: fwrite(): send of 15 bytes failed with errno=1 Operation not permitted
in /home/advancegzw/www/folder/include/SampQueryAPI.php on line 72
Notice: fwrite(): send of 15 bytes failed with errno=1 Operation not
permitted in /home/advancegzw/www/folder/include/SampQueryAPI.php on
line 72
Notice: fwrite(): send of 15 bytes failed with errno=1 Operation not
permitted in /home/advancegzw/www/folder/include/SampQueryAPI.php on
line 72
Line 72 is fwrite() obviously:
fwrite($this->rSocket, $sPacket);
Is there a possibility that the hosting company blocked outgoing UDP? Or is there another cause?
I am trying to access my gmail inbox using imap. I have applied almost all the possible solutions available here and also in google. But i am facing the same issue.
Below is my code :
$hostname = "{imap.gmail.com:993/imap/ssl/novalidate-cert}";
$mailbox = imap_open($hostname, 'my gmail account', 'my gmail password');
if ($mailbox)
{
echo 'if';
}
else
{
echo 'else';
}
exit;
When i run this code in to my local system it will give me some message like this :
Warning: imap_open(): Couldn't open stream {imap.gmail.com:993/imap/ssl/novalidate-cert} in D:\xampp\htdocs\php-imap-mailboxes\test-mail.php on line 4
else
Notice: Unknown: [ALERT] Please log in via your web browser: https://support.google.com/mail/accounts/answer/78754 (Failure) (errflg=1) in Unknown on line 0
Notice: Unknown: [ALERT] Please log in via your web browser: https://support.google.com/mail/accounts/answer/78754 (Failure) (errflg=1) in Unknown on line 0
Notice: Unknown: [ALERT] Please log in via your web browser: https://support.google.com/mail/accounts/answer/78754 (Failure) (errflg=1) in Unknown on line 0
Notice: Unknown: Too many login failures (errflg=2) in Unknown on line 0
I am running this script in to my local system. Please help me in to this as i have already spent lot's of time in this issue.
Thanks,
Ali
Make sure you have OpenSSL installed.
Here is a related discussion on google groups.
https://groups.google.com/forum/#!topic/comp.lang.php/JB5hm8cKi_Q
I'm setting up an email 'proxy-like' where notification emails are sent to the user that he has subscribed to, but he can reply to the email notification#site.com which should contain his reply. On the server-side I want to be able to read his email and add his reply to the database - the email is stored in the notification user inbox which is great, now to be able to read it with PHP.
So, I've been looking around for solutions for this, many solutions were IMAP so I thought I'd give a try but I cannot seem to figure my connection my server to open the inbox. I've adjusted to different ports, but none of them are able to connect.
imap_open("{localhost/imap:143}", "notification", "password");
I get errors like this:
Warning: imap_open(): Couldn't open stream {localhost/imap:143} in /var/www/site.com/www/mail.php on line 8
bool(false)
Notice: Unknown: Connection failed to localhost,143: Connection refused (errflg=1) in Unknown on line 0
Notice: Unknown: Connection failed to localhost,143: Connection refused (errflg=1) in Unknown on line 0
Notice: Unknown: Connection failed to localhost,143: Connection refused (errflg=1) in Unknown on line 0
Notice: Unknown: Connection failed to localhost,143: Connection refused (errflg=2) in Unknown on line 0
I don't understand, obviously this is my first time trying this but what is it that I'm clearly doing wrong with the connection?
EDIT: I started courier-imap now I get this:
Notice: Unknown: [CLOSED] IMAP connection broken (server response) (errflg=1) in Unknown on line 0
Notice: Unknown: [ALERT] Fatal error: No such file or directory: No such file or directory in Unknown on line 0
You are asking for basic debugging here, so I try, maybe this machtes
Have you tried to specify a mailbox? And btw you should actually use the right syntax, it is host:port/protocol whereas imap is the default protocol and you can leave it out:
imap_open("{localhost:143}INBOX", "notification", "password");
^^^^^^^^^^^^^ ^^^^^
Please compare with the many examples and notes on imap_openDocs.
Also as this is debugging, try:
var_dump(imap_errors(), imap_alerts());
Happy debugging.
I had exactly the same problem on my Ubuntu 11.04 system, and I've solved by creating the "Maildir" folders in my home directory (as described here) with the following commands:
cd ~
maildirmake Maildir
maildirmake Maildir/.Drafts
maildirmake Maildir/.Sent
maildirmake Maildir/.Trash
maildirmake Maildir/.Templates
chmod -R 700 Maildir
First of all, you should check for errors in the log file "/var/log/syslog" (for example by executing the command sudo tail /var/log/syslog).
In my log I had noticed the following error: imapd: chdir Maildir: No such file or directory.
So I've checked the configuration file "/etc/courier/imapd" and I saw that the MAILDIRPATH option was set to "Maildir":
#
# MAILDIRPATH - directory name of the maildir directory.
#
MAILDIRPATH=Maildir
Then I've created the "Maildir" folders as described above, and the "imap_open()" function finally worked.