Setting up gmail with imap in PHP on Mac using MAMP PRO - php

I've been trying to use PHP to access gmail but I can't get it to work.
I'm not sure if it's MAMP PRO's issue. I'm using MAMP PRO 2.0.3
Here is my code:
$server="{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX";
$inbox = imap_open($server,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error());
And the error I got was:
PHP Notice: Unknown: Can't open mailbox {imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX: invalid remote specification (errflg=2) in Unknown on line 0

After some research, I have found out that MAMP PRO doesn't have imap-ssl installed and therefore it cannot connect to gmail server since it requires ssl.
Instead, used PHPMailer library.

Related

IMAP protocol "unknown error(10057)"

i'm having a big trouble with the IMAP protocol in PHP.
I tried so many different ways to gather emails from an Gmail account but nothing works for me.
I'm using a WampServer 3.1.0 localhost with every version of every services up to date (except PHP, i'm not using 7.1.9 but the 7.0.23 one)
Here is the code for a Gmail attempt :
<?php
$hostname = '{imap.gmail.com:993/imap/ssl/novalidate-cert}';
$username = 'myemail#gmail.com'; $password = 'mypassword';
$inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error());
print_r(imap_errors());
?>
Here are the errors :
Warning: imap_open(): Couldn't open stream
{imap.gmail.com:993/imap/ssl/novalidate-cert} in
C:\wamp64\www\Projet_entreprise\imap_03bis_list.php on line 4
Notice: Unknown: Can't connect to gmail-imap.l.google.com,993: Unknown error (10057) (errflg=1) in Unknown on line 0
Notice: Unknown: Can't connect to gmail-imap.l.google.com,993: Unknown error (10057) (errflg=2) in Unknown on line 0
(My password is only numbers so i tried with and without quotes, same issue).
Even if I activated the IMAP Protocol in the Gmail account settings and the PHP extensions "php_imap" and "php_openssl" are enabled (green validate icon), same issue.
I'd really be grateful if you could try to help me ...
Thank you all for reading and have a good day.

PEAR/POP3 connects to mailserver, php-imap doesn't

We have a php script to handle bounce mails. Now I have to take care of switching from the PEAR NET/POP3 library to the native-ish php-imap library.
The mailserver listens on a remote server on port 110 without ssl (obviously POP3).
However I am unable to open a connection to that server using the php-imap library using the following code:
imap_open("{example.com:110/pop3/notls}INBOX", $username, $password);
This results in the following errors:
Warning: imap_open(): Couldn't open stream {example.com:110/pop3/notls}INBOX in C:\xampp\htdocs\bounce-processing\info.php on line 1
Notice: Unknown: POP3 connection broken in response (errflg=2) in Unknown on line 0
The following PEAR POP3 implementation still works:
require("Net/POP3.php");
$pop3 = new Net_POP3();
$pop3->connect('example.com', 110)
$pop3->login($username, $password);
What I already tried:
imap_open("{IP-ADDRESS:110/pop3/notls}INBOX", $username, $password);
imap_open("{IP-ADDRESS:110/pop3/notls/user=$username}INBOX", $username, $password);
NOTE: I also tested this on different setups (CentOS / Apache 2.2, Ubuntu 14.04 / nginx, PHP 5.4, PHP 5.5, PHP 5.6, no different outcome.
What can I do? Debugging did not really help me - and that the pear class works freaks me out.
Thanks in advance!
EDIT: php binary is compiled with imap / ssl and the php-imap extension is enabled in the php.ini. If you know another future-proof way to make php talk to a pop3 mailserver, let me know. We don't want to use frameworks such as phpmailer etc.
EDIT2: telnet login works with a success rate of 40%. I was able to successfully log in 4 out of 10 times with correct credentials.
Output of the CAPA command:
CAPA
+OK Here's what I can do:
STLS
TOP
USER
LOGIN-DELAY 10
PIPELINING
UIDL
IMPLEMENTATION Courier Mail Server
.
I don't know if thats important, but the mailserver is in fact hosted by a dedicated server housing and hosting company.
EDIT3: Trying to connect via
{IP_ADDRESS:110/pop3}
returns the following errors:
Warning: imap_open(): Couldn't open stream {IP_ADDRESS:110/pop3} in C:\xampp\htdocs\bounce-processing\index.php on line 12
Notice: Unknown: Certificate failure for IP_ADDRESS: Server name does not match certificate.
Appending the flag novalidate-cert leads to a timeout.

php imap_open giving issues connecting

I am having some issues with imap_open.
This is the error I am getting:
Message: imap_open(): Couldn't open stream
{imap-mail.outlook.com:993/imap/ssl/novalidate-cert}INBOX
No matter if its imap using ssl on port 993 or pop ssl on port 995, I am getting the same error.
Message:
Unknown: Can't open mailbox
{imap-mail.outlook.com:993/imap/ssl/novalidate-cert}INBOX: invalid
remote specification (errflg=2)
I have the following setup:
Mac OSX Yosemite
Mamp Pro running PHP 5.6.10
Here is what I've done to troubleshoot:
I have apple mail setup to check my gmail account using imap ssl on port 993. I will assume if apple mail can retrieve mail, the port is open.
I went to Security and Privacy and did a PORT SCAN... 993 and 995 were not open... strange.
I do not have Mac Firewall enabled.
When using non ssl, on port 110 pop, this appears to be working fine.
Can anyone assist to see what may be the cause.
Check phpinfo() to see if php is complied --with-imap-ssl
http://www.bartvanasselt.nl/mamp-pro-using-imap-with-ssl/
Also can try tunneling:
Workaround for PHP IMAP functions? Trying to work with incoming email on localhost using XAMPP

PHPMailer error: "unable to connect to :25"

When I was trying to send an email using the PHPMailer class, I had the following error:
Warning: fsockopen() [function.fsockopen]: unable to connect to :25 (No connection could be made because the target machine actively refused it. ) in C:\Users\Testing\Downloads\PHPMailer\phpmailer\class.smtp.php on line 105
Can anyone help me?
unable to connect to :25 is an indication that you forgot to enter a server address in the configuration.
Make sure you are specifying a valid SMTP server address when initializing PHPMailer.

php codeigniter mail function not working

i wa trying to do mail with php codeigner, but unfortunately its not working. the error which i got was the following; somebody please help me..
A PHP Error was encountered
Severity: Warning
Message: fsockopen() [function.fsockopen]: unable to connect to localhost:8025 (Connection refused)
Filename: libraries/smtp.php
Line Number: 105
Thanks in advance
Ahamed
Apparently you are trying to connect to port 8025, and this fails. The default smtp port is 25, so either you used the wrong port number or there is no mail service running on port 8025 on localhost, but whatever the cause this is something you should probably change in your configuration somewhere.
Another option is to change the mail protocol from smtp to native php mail, refer to the CodeIgniter docs on how to do this (and make sure you set this up correctly - especially if you are using Windows, check php.ini).

Categories