How to fix: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed - email

I am currently working on cygwin.
I was trying to send and email through phpmailer using my gmail account and the following script (obtained online, then hacked):
<?php
require 'phpmailer/PHPMailerAutoload.php';
$mail = new PHPMailer(true);
try {
$mail->ISSMTP();
$mail->Host='smtp.gmail.com';
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => true,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
$mail->Port = 587;
$mail->Username = "myemail#gmail.com";
$mail->Password = "MyGooglePassword";
$mail->setFrom('myemail#gmail.com', 'my name1');
$mail->addAddress('anotheremail#email.fr', 'my name2');
$mail->Subject = 'PHPMailer Exceptions test';
$mail->Body = "Hi, This is the HTML BODY "; //HTML Body
$mail->AltBody = 'This is a plain-text message body';
$mail->send();
echo "Message sent!";
} catch (phpmailerException $e) {
echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
echo $e->getMessage();
}
I have seen multiple solutions on stack overflow, but I haven't found any telling how to properly self sign my localhost so that I would be able to avoid this error message:
PHP Warning: stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /usr/share/pear/phpmailer/class.smtp.php on line 346
2015-11-30 08:47:15 SMTP Error: Could not connect to SMTP host.
2015-11-30 08:47:15 CLIENT -> SERVER: QUIT
2015-11-30 08:47:15 SMTP ERROR: QUIT command failed
I have also tried resolving the issues by setting 'verify_peer' to false at "$mail->SMTPOptions" (as recommended in: PHPMailer - SSL3_GET_SERVER_CERTIFICATE:certificate verify failed), but when I do that, my gmail account refuse to cooperate saying that the signing attempt does not meet modern security standard!!
Please let me know if there is a proper tutorial that would allow me to properly set my ssl and have the email successfuly sent with the proper verifications.
Here is below a link to the gmail message: Gmail - sign in attempt prevented

Related

phpmailer 6.0 success message but no mail received using gmail as relay

I've tried a bunch of alterations to my code but with no effect. The code itself does not return any errors but instead gives a success message. I am using gmail as my relay.
P.S, I commented out $mail->IsSMTP(); because I saw a similar question here that used it as a fix, I was getting an "smtp failed to connect" error.
I am using PHPmailer 6.0.
Here is my code:
<?php
require_once('vendor/autoload.php');
define('GUSER', 'example#gmail.com'); // GMail username
define('GPWD', '*********'); // GMail password
function smtpmailer($to, $from, $from_name, $subject, $body) {
global $error;
$mail = new PHPMailer\PHPMailer\PHPMailer(true); // create a new object
//$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 4; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'tls'; // secure transfer enabled REQUIRED for GMail
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->Username = GUSER;
$mail->Password = GPWD;
$mail->SetFrom($from, $from_name);
$mail->Subject = $subject;
$mail->Body = $body;
$mail->AddAddress($to);
if(!$mail->Send()) {
$error = 'Mail error: '.$mail->ErrorInfo;
return false;
} else {
$error = 'Message sent!';
return true;
}
}
smtpmailer('to#mail.com', 'from#mail.com', 'yourName', 'test mail message', 'Hello World!');
if (smtpmailer('to#mail.com', 'from#mail.com', 'yourName', 'test mail message', 'Hello World!')) {
// do something
}
if (!empty($error)) echo $error;
?>
If I uncomment $mail->IsSMTP(); I get this error log:
2017-12-27 07:58:54 Connection: opening to smtp.gmail.com:465, timeout=300, options=array()
2017-12-27 07:58:54 Connection failed. Error #2: stream_socket_client(): unable to connect to smtp.gmail.com:465 (Network is unreachable) [/srv/disk2/2564570/www/consorttest.dx.am/vendor/phpmailer/phpmailer/src/SMTP.php line 325]
2017-12-27 07:58:54 SMTP ERROR: Failed to connect to server: Network is unreachable (101)
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Fatal error: Uncaught PHPMailer\PHPMailer\Exception: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting in /srv/disk2/2564570/www/consorttest.dx.am/vendor/phpmailer/phpmailer/src/PHPMailer.php:1726 Stack trace: #0 /srv/disk2/2564570/www/consorttest.dx.am/vendor/phpmailer/phpmailer/src/PHPMailer.php(1481): PHPMailer\PHPMailer\PHPMailer->smtpSend('Date: Wed, 27 D...', 'Hello World!\r\n') #1 /srv/disk2/2564570/www/consorttest.dx.am/vendor/phpmailer/phpmailer/src/PHPMailer.php(1320): PHPMailer\PHPMailer\PHPMailer->postSend() #2 /srv/disk2/2564570/www/consorttest.dx.am/mailtest.php(23): PHPMailer\PHPMailer\PHPMailer->send() #3 /srv/disk2/2564570/www/consorttest.dx.am/mailtest.php(32): smtpmailer('to#mail.com', 'from#mail.com', 'yourName', 'test mail messa...', 'Hello World!') #4 {main} thrown in /srv/disk2/2564570/www/consorttest.dx.am/vendor/phpmailer/phpmailer/src/PHPMailer.php on line 1726
You're not "using gmail as your relay" if you comment out isSMTP() because then it's not using SMTP at all, and will ignore all your SMTP settings. You're sending via your local mail server using PHP's built-in mail function.
When sending through gmail, you can't use arbitrary from addresses, though you can preset aliases in your gmail account.
You've based your code on a very old and obsolete example - use the gmail one provided with PHPMailer.
The most important part of the error output is: Network is unreachable - that probably means your ISP blocks outbound SMTP - are you by any chance using GoDaddy?
Next up, you have a basic misconfiguration: you're connecting to port 465 using SMTPSecure = 'tls', which means it will try to use SMTP+STARTTLS explicit TLS encryption, and that just won't work on port 465. This is a key reason to use the provided examples - they don't make basic errors like this.
Every one of these things is covered in the troubleshooting guide the error links to.

mailer error : SMTP connect() using phpmailer

I am trying to send mail using PHPMailer but when i try i get error like
MEssage Could not be sent. SMTP connect() failed
When i debug the code, I got following message:
CLIENT -> SERVER: EHLO 127.0.0.1
CLIENT -> SERVER: AUTH LOGIN
CLIENT -> SERVER: dGFsYWFzaDIwMTdAc29jZXQuZWR1Lmlu
CLIENT -> SERVER: c29jZXRAMTIz
SMTP ERROR: Password command failed: 534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbt5534-5.7.14 V4dQliEGa4GCkfkxZoZVAX296_Q1jP9UHhiGXQShhTqxshYg2snLu2nKW4UIhB3k4X6Kqt534-5.7.14 Q6rvXHk5aNrXU22BwfYC_VVWeFwr8-216IZQmLpq0AA9NXNaQGQHeW1ZJNQGrvUBs6f8HQ534-5.7.14 OLspMG5dlPjNzvsAGG6lHHJ7eVYFFv8sZEYvxaAkvJR1zHk27qNpB1Gc5Ld32Fbs1SpC2H534-5.7.14 981OqnvjQrzYQCbcwIwVrqfjoVQPk> Please log in via your web browser and534-5.7.14 then try again.534-5.7.14 Learn more at534 5.7.14 https://support.google.com/mail/answer/78754 n79sm9364629pfj.31 - gsmtp
SMTP Error: Could not authenticate.
CLIENT -> SERVER: QUIT
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Message could not be sent.Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Below is the code which i have tried:
require '../phpmailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP();
$mail->SMTPDebug = 1;
$mail->Debugoutput = 'html';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->SMTPSecure = 'ssl';
$mail->SMTPAuth = true;
$mail->Username = 'mymail#gmail.com'; // SMTP username
$mail->Password = 'mypass';
$mail->setFrom('mymail#gmail.com', 'Mailer');
$mail->addAddress($user_email, $user_name);
$mail->Subject = 'Registration acknowledgment GTU Techfest Zone - 1';
$mail->Body = '<b>You have registerd for following events:</b>'."\r\n";
if(!$mail->send())
{
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
}
else
{
echo "unsuccessfull".mysql_error();
}
I have tried several solutions but its not working. I am working on localhost.I have also changed my xampp settings to send mail

Phpmailer doesn't work on wamp on windows server 2008

i'm trying to send an email using phpmailer, it works fine on my laptop using xampp localhost server but when i tried to run the php class on my windows server 2008 with wamp installed on it it didn't work.
i already checked if the ssl is enabled from the php.ini
i'm getting this error:
2016-09-06 10:01:22 Connection: opening to smtp.mail.yahoo.com:587, timeout=300, options=array ( ) 2016-09-06 10:01:44 SMTP ERROR: Failed to connect to server: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. (10060) 2016-09-06 10:01:44 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Message could not be sent.Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
here's my code:
SendOutlook();
function SendOutlook(){
//$recipient = 'alghomlas.dk#pg.com';
require 'PHPMailer/PHPMailerAutoload.php';
$Emp_recipient = "alghomlas.dk#pg.com";
$mail = new PHPMailer;
$mail->SMTPDebug = 4; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = "smtp.mail.yahoo.com"; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'xxxxxxxxx'; // SMTP username (server username)
$mail->Password = 'xxxxx'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom('alghomlas.dk#yahoo.com', 'One');
$mail->addAddress($Emp_recipient,"dalal alghomlas"); // Add a recipient
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'test';
$mail->Body = "scheduled on your outlook calender";
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit();
}else {
echo '<p>Message has been sent</p>';
}
echo !extension_loaded('openssl')?"Not Available":"Available";
AddOutlookEvent($Mng_recipient, $Emp_recipient, $Mng_Name, $Emp_Name, $Date, $Time);
}

PHPMailer failing with ssl

I'm having troubles sending an email with PHPMailer through my SMTP which is ssl enabled.
$mail = new PHPMailer;
// HTML email!
$mail->IsHTML(true);
$mail->isSMTP();
$mail->SMTPDebug = 0;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = "server.co.tz";
//Set the SMTP port number - likely to be 25, 465 or 587
$mail->Port = 465;
$mail->SMTPSecure = "ssl";
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication
$mail->Username = "xxxxxxx";
//Password to use for SMTP authentication
$mail->Password = "yyyyyyy";
When i run the script I get the following error:
Mailer Error: SMTP connect() failed.
And on the exim4 logs:
2016-02-24 11:02:20 TLS error on connection from [197.215.254.114] (gnutls_handshake): A TLS fatal alert has been received.
I have no clue on what is going wrong here.
I use the SMTP regurarly for my email clients and the SSL certificate is a valid one.
Update:
Got latest version and set debug to 3 but still no luck:
Connection: opening to ssl://fsm.co.tz:465, timeout=300, options=array ()
SMTP ERROR: Failed to connect to server: (0)
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
As of today #PHPMailer version 6.1.4
These worked for me:-
$email->SMTPDebug = SMTP::DEBUG_SERVER;
$email->isSMTP();
$email->Host = 'host';
$email->SMTPAuth = true;
$email->Username = 'username';
$email->Password = 'password';
$email->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
$email->Port = 465;
The solution is to add the following to the configuration:
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => false
)
);

SMTP gmail with PHPMailer

I have a problem with PHPMailer. Last month I did with the same script and worked great.
This is the code:
$alemail = 'anotherof#yahoo.com';
//send email
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'someof#mydomain.com';
$mail->Password = 'password';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->setFrom('someof#mydomain.com', 'my name');
$mail->addReplyTo('someof#mydomain.com', 'my name');
$mail->addAddress($alemail);
$mail->isHTML(true);
$mail->Subject = 'test';
$mail->Body = 'hello test';
if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
}
and the error is:
2015-02-04 09:01:01 SMTP ERROR: Failed to connect to server: Network is unreachable (101) 2015-02-04 09:01:01 SMTP connect() failed. Message was not sent.Mailer error: SMTP connect() failed.
I already check with my server provider and they said no problem with their server side.
I also already do SMTP relay setting on google apps but still not working.
any suggestion?
thanks in advance
Just for update.. I already solved the problem a few days ago.
Apparently it is server's problem. But when I asked my server provider, they claimed there was nothing wrong with the server smtp connection based on telnet result check:
Trying 64.233.169.109...
Connected to gmail-smtp-msa.l.google.com.
Escape character is '^]'.
220 mx.google.com ESMTP m65sm1615043oif.5 - gsmtp
^]
So I asked them to relocate my files to other server and now the PHPMailer script working great.
Thank you #Synchro for your respond.