7

I'm using below code for sending mail. It's working fine in gmail server, but it's not working for my domain.
It's showing an error like

Connection failed. Error #2: stream_socket_enable_crypto(): Peer certificate CN=`*.999servers.com'

How can I solve this issue?
This is my code so far:

require("PHPMailer/src/PHPMailer.php");
require("PHPMailer/src/SMTP.php");
$mail = new PHPMailer\PHPMailer\PHPMailer();
$mail = new PHPMailer\PHPMailer\PHPMailer(true);
$mail->IsSMTP();
$mail->SMTPDebug = 4;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tls';
$mail->Host = "mail.mydomain.in";
$mail->Port = 587;
$mail->IsHTML(true);
$mail->Username = "mail";
$mail->Password = "password";

$mail->SetFrom($admin_user_mail);
$mail->AddAddress($login_user_mail);
$mail->AddCC($admin_user_mail);
$mail->Subject = "Mail Subject";
$mail->Body = "Mail Content";


if($mail->send()) 
{   
    echo "Mail Send";
} else 
{
    echo "Mail Not sent";
}
5
  • Does your mail server support TLS or even SSL
    – RiggsFolly
    Commented Oct 11, 2018 at 17:10
  • Yes its support both TLS and SSL. Commented Oct 11, 2018 at 17:15
  • 2
    It looks like your SMTP server has an out of date or invalid TLS certificate.
    – tadman
    Commented Oct 11, 2018 at 17:34
  • Hi tadman. How can I solve this issue. What I want to change in my code or else I want to change in server setting? Commented Oct 12, 2018 at 7:35
  • Hi, still I can't able to solve this issue. Almost last two days I'm trying with this code still mail not sending. kindly let me know the solution if any one know. Commented Oct 13, 2018 at 19:07

1 Answer 1

9
$mail->SMTPOptions = array(
       'ssl' => array(
                'verify_peer' => false,
                'verify_peer_name' => false,
                'allow_self_signed' => true
            )
        );    
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.