使用phpmailer发送消息

时间:2018-03-11 17:14:30

标签: php html email phpmailer

我试图通过发送激活电子邮件来创建注册页面,但我使用phpmailer收到此错误:

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 C:\xampp\htdocs\Exercicis\M08+M09\phpmailer\class.smtp.php on line 269

我已经搜索了很多信息,但我找不到任何解决方法 我的代码:

<?php  
$usuario = $_POST['uname'];
$passwrod = $_POST['psw1'];
$correo = $_POST['email'];
include('phpmailer/class.phpmailer.php');
include('phpmailer/class.smtp.php');
$password = rand(1999, 9999);   
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tls';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->Username = 'example@gmail.com';
$mail->Password = 'secret';
$mail->From = 'example@gmail.com';
$mail->FromName = 'Administrador PHP';
$mail->Subject = 'Subject del Email';
$mail->AltBody = 'Password: "'. $password .'"';
$mail->AltBody = 'Registrat: http://localhost:3000/Practica/panell_reg.php';
$mail->MsgHTML('Registrat: http://localhost:3000/Practica/panell_reg.php<br>Password: "'. $password .'"<br>.');
$mail->AddAddress($correo);
//$mail->SMTPDebug = 4;
$mail->IsHTML(true);

if(!$mail->Send()) {
      echo 'Error: ' . $mail->ErrorInfo;
} else {
      echo 'Mensaje enviado correctamente';
}
?>

1 个答案:

答案 0 :(得分:2)

PHP 5.6默认验证SSL证书,如果存在与证书相关的问题,您将收到此错误。正确的解决方案是修复您的SSL配置。您可以在PHPMailer https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting的完整文档中了解此错误吗?