php - PHPMailer - OpenSSL Error -
based on example phpmailer provides have script below,
date_default_timezone_set('etc/utc'); require './phpmailerautoload.php'; $mail = new phpmailer; $mail->issmtp(); $mail->smtpdebug = 2; $mail->debugoutput = 'html'; $mail->host = 'smtp.gmail.com'; $mail->port = 587; $mail->smtpsecure = 'tls'; $mail->smtpauth = true; $mail->username = "myemail@example.com"; $mail->password = "********"; $mail->setfrom('mymail@example.com', 'first last'); $mail->addreplyto('myemail@example.com', 'first last'); $mail->addaddress('toemail@example.com', 'first last'); $mail->subject = 'phpmailer gmail smtp test'; $mail->body = "example"; $mail->altbody = 'this plain-text message body'; if (!$mail->send()) { echo "mailer error: " . $mail->errorinfo; } else { echo "message sent!"; }
even if same original example, cannot work.
the error
warning: stream_socket_enable_crypto(): ssl operation failed code 1. openssl error messages: error:14090086:ssl routines:ssl3_get_server_certificate:certificate verify failed in /opt/lampp/htdocs/webmail_client_practise/class.smtp.php on line 344 smtp error: not connect smtp host.
notice: openssl extension in php.ini
file opened.
this because you're running php 5.6 , it's verifying certs, server presenting invalid certs it's failing. both phpmailer , php correct in doing - code not @ fault. can either fix mail server, or suggests in the troubleshooting guide, is:
$mail->smtpoptions = array( 'ssl' => array( 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true ) );
and guide says, you should not unless have to - it's compromising security.
Comments
Post a Comment