0

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
Fabrizio Mazzoni
  • 1,831
  • 2
  • 24
  • 46

2 Answers2

0

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;   
burf
  • 153
  • 2
  • 8
-2

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
    )
);
Fabrizio Mazzoni
  • 1,831
  • 2
  • 24
  • 46
  • It's not really a solution, but a (temporary) workaround. Nevertheless, this is "correct" in that it can get you up-and-running quickly while testing with self-signed or otherwise bad certificates. If this works, the "proper" solution is to get a proper certificate for your mail server. – Micha Sep 05 '17 at 09:08