Cant send mails with PHPMailer
I can not send mails (I want to send them directly from Gmail, not with the mail () function), I'm trying the PHPMailer library and when I run it from a URL It does not work, it disconnects me from the server in the middle of the connection. If I do from SSH, with the root user, all right, send the mails correctly.
The option: whm > security center > SMTP Restrictions is Disable.
Now if I run from the browser that same, it does not work:
In: /var/log/apache2/error_log does not register errors.
It seems that you are just starting to send the mail, close the connection. What can be the problem? The code of the script is the follow:
And the PHP script returns:
2017-07-30 21:46:54 SERVER -> CLIENT: 220-hosting.xxxx.cl ESMTP Exim 4.89 # 1 Sun, 30 Jul 2017 17:46:54 -0400 220-We do not authorize the use of this system To transport unsolicited, 220 and / or bulk email.
2017-07-30 21:46:54 CLIENT -> SERVER: EHLO xxxx.com.ar
2017-07-30 21:46:54 SERVER -> CLIENT: 250-hosting.xxxx.cl Hello vovstore.com.ar [xxx.xxx.xxx.xxx] 250-SIZE 52428800250-8BITMIME250-PIPELINING250-AUTH PLAIN LOGIN250-STARTTLS250 HELP
2017-07-30 21:46:54 CLIENT -> SERVER: STARTTLS
2017-07-30 21:46:54 SERVER -> CLIENT: 220 TLS go ahead
SMTP Error: Could not connect to SMTP host.
2017-07-30 21:46:54 CLIENT -> SERVER: QUIT
2017-07-30 21:46:54 SERVER -> CLIENT: 221 hosting.xxxx.cl closing connection
SMTP connect () failed. Troubleshooting " PHPMailer/PHPMailer Wiki " GitHub
Mailer Error: SMTP connect () failed. Troubleshooting " PHPMailer/PHPMailer Wiki " GitHub
It seems that you are just starting to send the mail, close the connection. What can be the problem? The code of the script is the follow:
isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 2;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = 'smtp.gmail.com';
// use
// $mail->Host = gethostbyname('smtp.gmail.com');
// if your network does not support SMTP over IPv6
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail->Port = 587;
//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'tls';
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication - use full email address for gmail
$mail->Username = "xxxxxxx@xxxxxxx.com.ar";
//Password to use for SMTP authentication
$mail->Password = "xxxxxxx";
//Set who the message is to be sent from
$mail->setFrom('xxxxxx@gmail.com', 'First Last');
//Set an alternative reply-to address
$mail->addReplyTo('xxxxxxx@gmail.com', 'First Last');
//Set who the message is to be sent to
$mail->addAddress('xxxxxxx@gmail.com', 'John Doe');
//Set the subject line
$mail->Subject = 'PHPMailer GMail SMTP test';
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';
//Attach an image file
$mail->addAttachment('images/phpmailer_mini.png');
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
-
Hi, Do you have any custom firewall rules or applications that could block that port? If yes then try to disable it. 0 -
The option: whm > security center > SMTP Restrictions is Disable.
Hello, Are you also using the CSF firewall? If so, check to see if the "SMTP_BLOCK" setting is enabled. Thank you.0 -
maybe somebody is try to find how can solve this problem vi /etc/csf/csf.conf section # SECTION:SMTP Settings just add your user smtp_allowuser : cpanel,myuser ( user is ftp login domain ) csf -r that is all 0
Please sign in to leave a comment.
Comments
3 comments