Cannot connect to mail server with phpmailer - php

I try to open php mailer file to text it and it says this:
Connection: opening to smtp.gmail.com:587, timeout=300, options=array ()
Connection: Failed to connect to server. Error number 2. "Error notice: stream_socket_client(): unable to connect to smtp.gmail.com:587 (No connection could be made because the target machine actively refused it.)
SMTP ERROR: Failed to connect to server: No connection could be made because the target machine actively refused it. (10061)
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Do you guys know how to fix it?

Try to turn on Access for less secure apps for your gmail. Suggest to use a new e-mail to do it. Because it is less secure.
https://support.google.com/accounts/answer/6010255?hl=en

Related

What is the reason for the PHPMailer error stream_select(): unable to select?

edit at 11/24/2022:The problem I solved, but the cause is not found, it may be a problem with the PHP source code. I re-downloaded the source code from the official PHP website and overwrite it, the problem disappeared.
My local environment is windows 10, PHPMailer will report this error in PHP 5.6, but it is normal in 7.0 and above, I haven't learned socket, I don't know how to troubleshoot this error.
There are two kinds of errors.
The first one is
Connection failed. Error #2: stream_select(): unable to select [11]: No such file or directory
this error is in the case of tls protocol, port 25.
The second one is
Connection failed. error #2: stream_select(): unable to select [11]: Resource temporarily unavailable.
this error occurs in the case of ssl protocol, port 465.
Both are caused by stream_select in PHPMailer/src/SMTP.php at line 1228.
debugging data
Connection: opening to ssl://smtp.qq.com:465, timeout=300, options=array()
Connection: opened
Connection failed. Error #2: stream_select(): unable to select [11]: Resource temporarily unavailable (max_fd=772) [\vendor\phpmailer\phpmailer\src\SMTP.php line 1228]
SMTP -> get_lines(): select failed (stream_select(): unable to select [11]: Resource temporarily unavailable (max_fd=772))
SERVER -> CLIENT:
Connection: closing due to error
Connection: closed
SMTP Error: Could not connect to SMTP host.

Can PHPMailer determine the precise reason for SMTP failure?

I'm currently writing a tool that helps users configure an SMTP send, and am using PHPMailer to achieve this. Presently I notify users if the SMTP operation was not successful, and I'd like to make this more specific.
In the source code, it says:
// The reason for failing to send will be in $mail->ErrorInfo
However, the contents of this property are not very specific. For example, for both a failed auth and an unreachable server, I get the identical error:
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
However, if I dig into the SMTP logs using PHPMailer's debug level 2, I get more useful information. For a failed auth:
2018-01-31 19:37:12 SERVER -> CLIENT: 535 Incorrect authentication data
2018-01-31 19:37:12 SMTP ERROR: Password command failed: 535 Incorrect authentication data
2018-01-31 19:37:12 SMTP Error: Could not authenticate.
For an unreachable server:
2018-01-31 21:12:34 SMTP ERROR: Failed to connect to server: php_network_getaddresses: getaddrinfo failed: Name or service not known (0)
So, it looks like this information is available, but it might vary between different mail server types. Is there any parsing of this in PHPMailer? I'd like reliable reason codes I can test, rather than searching for strings in logs that might not match for every server.
I expect there are other failure types as well, such as a badly configured certificate.

SMTP ERROR: Failed to connect to server: Connection timed out (110) in php

I have a problem. I use phpmailer smtp gmail it works on localhost but when I upload that it is showing me these errors
SMTP ERROR: Failed to connect to server: Connection timed out (110)
SMTP connect() failed.
Mailer Error: SMTP connect() failed.
Any solution please. I am using phpmailer first time so I have no idea about it, thanks
The network that your server is running on may be blocking outgoing connections on the port that you are using to connect to smtp.gmail.com. You can test is this is happening, by using telnet to connect from the server to smtp.gmail.com on whichever port you are trying to connect on.
it looks as if your server is blocking access/connections to SMTP ports.

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 imap get connection failed error

Warning: imap_open() [function.imap-open]: Couldn't open stream {imap.gmail.com:993/imap/ssl}INBOX in /home/happy/public_html/source/imap/fet_mail_from_email_add.php on line 7
can't connect: Can't connect to gmail-imap.l.google.com,993: Connection timed out
my snippet is
$mbox = imap_open("{imap.gmail.com:993/imap/ssl}INBOX",
"user#gmail.com","somesecretpassword")
or die("can't connect: " . imap_last_error());
Like the error message point out there is a network timeout/connection failure happening.
Make sure any network equipment (Firewall, router with ACL, etc ...) don't disallow to connect to the TCP port 993.
You would probably make sure you can connect from the server to Gmail server using ssh and trying with telnet first, if that test is ok try with PHP.

Categories