0

Using IIS 7 and PHP7.1 We i managed to connect my server to our SMTP server (on a different IP Address) I did this by quiet simply editing my php.ini file

SMTP = mail.<Domain>.co.uk
smtp_port = 25
sendmail_from = mail@<Domain>.co.uk

And by calling a php script, an email was sent

<?php
   $msg = "Hello Do I Work   Im From the Server";
   mail("joe@<Domain>.co.uk","My subject",$msg);
?>

This worked providing that the email recipient was on the same domain.

However the request came for emails to be sent to anyone. When i tried this, using above code and settings i got this error

PHP Warning:  mail(): SMTP server response: 550 5.7.1 Unable to relay in …

Having a quick read i found that PHP 7.1 don't allow smtp passwords which the lack caused the above error. Id need a external mail library 1) Was this correct

i downloaded and installed phpmailer (i can change this if required) and ran the following script

<?php
    require_once "PHPMailerAutoload.php";
    $mail = new PHPMailer;
    $mail->SMTPDebug = 3;                               
    $mail->isSMTP();            
    $mail->Host = "mail.<Domain>.co.uk";
    $mail->SMTPAuth = true;                          
    $mail->Username = "mail@<Domain>.co.uk";                 
    $mail->Password = "<Password>";                           
    $mail->SMTPSecure = "tls";                           
    $mail->Port = 25;
    $mail->From = "mail@<Domain>.co.uk";
    $mail->FromName = "Mail";
    $mail->addAddress("joe@<Domain>.co.uk"); 
    $mail->addReplyTo("mail@<Domain>.co.uk", "Reply");
    $mail->isHTML(true);
    $mail->Subject = "Test";
    $mail->Body = "From the Server";

    if(!$mail->send()) 
   {
        echo "Mailer Error: " . $mail->ErrorInfo;
    }
    else
      {
             echo "Message has been sent successfully";
    }
?>

I ran this and got the error

2017-05-19 11:57:52 Extension missing: openssl Mailer Error: Extension missing: openssl

So i uncommented this in my php.ini

extension=php_openssl.dll

Reran the script and got

2017-05-19 11:59:14 Connection: opening to mail.<Domain>.co.uk:25, timeout=300, options=array ( ) 2017-05-19 11:59:14   Connection: opened         2017-05-19 11:59:14  
SERVER -> CLIENT: 220 PATHEX01.pathways.local Microsoft ESMTP MAIL Service ready at Fri, 19 May 2017 12:59:14 +0100 2017-05-19 11:59:14 
CLIENT -> SERVER: EHLO www.<Domain>.co.uk 2017-05-19 11:59:14   
SERVER -> CLIENT: 250-PATHEX01.pathways.local Hello [146.255.105.211] 250-SIZE 37748736 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-STARTTLS 250-X-ANONYMOUSTLS 250-AUTH NTLM 250-X-EXPS GSSAPI NTLM 250-8BITMIME 250-BINARYMIME 250-CHUNKING 250 XRDST 2017-05-19 11:59:14  
CLIENT -> SERVER: STARTTLS 2017-05-19 11:59:14  
SERVER -> CLIENT: 220 2.0.0 SMTP server ready 2017-05-19 11:59:15   Connection failed. Error #2: stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed [C:\inetpub\wwwroot\EmailTest\class.smtp.php line 369] 2017-05-19 11:59:15  SMTP Error: Could not connect to SMTP host. 2017-05-19 11:59:15 
CLIENT -> SERVER: QUIT 2017-05-19 11:59:15  
SERVER -> CLIENT: 2017-05-19 11:59:15   SMTP ERROR: QUIT command failed: 2017-05-19 11:59:15    Connection: closed 2017-05-19 11:59:15  SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

Can anyone suggest what I'm doing wrong? Thanks

Display Name
  • 1,025
  • 2
  • 15
  • 34
  • The important part: "certificate verify failed". This exact problem is very well known, covered in the PHPMailer troubleshooting guide that the error message links to, and has many duplicate questions on here. Please *read your error messages* before asking questions - it will get you the answers much faster! – Synchro May 19 '17 at 12:43
  • Possible duplicate of [PHPMailer generates PHP Warning: stream\_socket\_enable\_crypto(): Peer certificate did not match expected](http://stackoverflow.com/questions/30371910/phpmailer-generates-php-warning-stream-socket-enable-crypto-peer-certificate) – Synchro May 19 '17 at 12:44

0 Answers0