Reputation: 21
I have written a new php script but I see some problem when I try to connect with server have a expired certificate:
I can use same smtp ip:port in windows program and its work fine.
I can use it and working with thunderbird but he give me certificate expired before send any thing
The code is below.
<?php
/**
* Created by PhpStorm.
* User: n0b0dy
* Date: 11/1/18
* Time: 9:40 PM
*/
require("/usr/share/php/libphp-phpmailer/class.phpmailer.php");
require '/usr/share/php/libphp-phpmailer/PHPMailerAutoload.php';
require '/usr/share/php/libphp-phpmailer/autoload.php';
require '/usr/share/php/libphp-phpmailer/class.smtp.php';
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
/**
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => true,
'verify_depth' => 3,
)
);
*/
$mail->SMTPDebug = 4; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = 0; // authentication enabled
#$mail->SMTPAutoTLS = false;
$mail->Host = 'ssl://75.101.161.108:465';
$mail->IsHTML(true);
$mail->SetFrom("[email protected]");##### Dont care about email because of problem with connection
$mail->Subject = "Test";
$mail->Body = "hello";
$mail->AddAddress("[email protected]");
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent";
}
?>
and this is a problem for Phpmailer
2018-11-02 06:38:23 Connection: opening to ssl://75.101.161.108:465, timeout=300, options=array (
)
2018-11-02 06:38:24 SMTP ERROR: Failed to connect to server: (0)
2018-11-02 06:38:24 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting%
B - pearemail with smtp setting and code here
<?php
require_once "Mail.php";
include('Mail/mime.php');
$html = "TEST";// HTML version of the email
$crlf = "\r\n";
$headers = array('From' => "Test<[email protected]>",'To' => '[email protected]', 'Return-Path' => '[email protected]', 'Subject' => 'Form Pear Email');
$mime = new Mail_mime($crlf);
$mime->setHTMLBody($html);
$body = $mime->get();
$headers = $mime->headers($headers);
$smtpinfo["host"] = 'ssl://75.101.161.108';
$smtpinfo["port"] = '465';
$smtpinfo["auth"] = "false";
$smtpinfo["socket_options"] = array('ssl' => array('verify_peer_name' => false,'verify_peer' => false,'allow_self_signed' => true));
$smtpinfo["timeout"] = "10";
$smtpinfo["debug"] = "true";
$smtp = Mail::factory('smtp',$smtpinfo);
$mail = $smtp->send('[email protected]', $headers, $body);
if (PEAR::isError($mail)) {
echo($mail->getMessage());
} else {
echo("WORKING\n");
}
?>
and related problem ,
DEBUG: Send: QUIT
Failed to connect to ssl://75.101.161.108:465 [SMTP: Failed to connect socket: stream_socket_client(): unable to connect to ssl://75.101.161.108:465 (Unknown error) (code: -1, response: )]
i have use openssl with this command
openssl s_client -connect 75.101.161.108:465
result
CONNECTED(00000003)
140527088361920:error:14094410:SSL routines:ssl3_read_bytes:sslv3 alert handshake failure:../ssl/record/rec_layer_s3.c:1399:SSL alert number 40
---
no peer certificate available
---
No client certificate CA names sent
---
SSL handshake has read 7 bytes and written 176 bytes
Verification: OK
---
New, (NONE), Cipher is (NONE)
Secure Renegotiation IS NOT supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
SSL-Session:
Protocol : TLSv1.2
Cipher : 0000
Session-ID:
Session-ID-ctx:
Master-Key:
PSK identity: None
PSK identity hint: None
SRP username: None
Start Time: 1541150392
Timeout : 7200 (sec)
Verify return code: 0 (ok)
Extended master secret: no
---
So please, can anyone can help me ?
Regards for erveryone
Upvotes: 2
Views: 2831
Reputation: 37810
First step: you're using an old version of PHPMailer; get the latest.
Base your code on the examples provided - in particular you should be using composer to load it, but with the old code you don't need to load classes and the autoloader.
The notice is bad. It's not just that it's expired, but that it's a mismatched name, expired, and not signed by a known CA. This suggests that your connection is being intercepted and redirected to somewhere other than what you're expecting. This is exactly what TLS is there to protect you from, and it is working as intended.
You should not disable certificate verification. Figure out what is happening to your connection (see the steps in the PHPMailer troubleshooting guide), and track down what your ISP does with outbound SMTP connections, then use openssl commands to inspect the certificate you're getting. We can't do any of this for you as you have hidden real host names.
Upvotes: 1