PHPMailer - SMTP Error: Could not connect to SMTP host

大城市里の小女人 提交于 2019-12-10 10:44:26

问题


I'm trying to send email using PHPMailer. When I tried sending the email from gmail account, it works perfectly fine. However, I would like to send the email from my own SMTP, but there seems to be an error. What could be the problem? Please help me. Thank you.

Using smtp.gmail.com :

$mail->SMTPDebug = 3;
$mail->isSMTP();                                      
$mail->Host = 'smtp.gmail.com';                 
$mail->SMTPAuth = true;                               
$mail->Username = 'myemail@gmail.com';                 
$mail->Password = 'password';                               
$mail->SMTPSecure = 'tls';                           
$mail->Port = 587; 

Using mail.distech.com.my :

require 'PHPMailerAutoload.php';

$mail = new PHPMailer;

$mail->SMTPDebug = 3;
$mail->isSMTP();                                      
$mail->Host = 'mail.distech.com.my';                    
$mail->SMTPAuth = true;                               
$mail->Username = 'myemail@distech.com.my';                 
$mail->Password = 'password';                           
$mail->SMTPSecure = 'tls';                            
$mail->Port = 587; 

$mail->From = 'myemail@distech.com.my';
$mail->addAddress('amalina@distech.com.my');     
$mail->Subject = 'Test';
$mail->Body    = 'Test message';

if(!$mail->send()) {
   echo 'Message could not be sent.';
   echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
   echo 'Message has been sent';
}

Error using mail.distech.com.my

2015-06-23 06:58:45 Connection: opening to mail.distech.com.my:587, timeout=300, options=array ( ) 
2015-06-23 06:58:45 Connection: opened 
2015-06-23 06:58:45 SERVER -> CLIENT: 220-server.firstonline-server16.com ESMTP Exim 4.85 #2 Tue, 23 Jun 2015 14:58:45 +0800 220-We do not authorize the use of this system to transport unsolicited, 220 and/or bulk e-mail. 
2015-06-23 06:58:45 CLIENT -> SERVER: EHLO 192.168.1.20 
2015-06-23 06:58:46 SERVER -> CLIENT: 250-server.firstonline-server16.com Hello 192.168.1.20 [115.135.120.220] 250-SIZE 52428800 250-8BITMIME 250-PIPELINING 250-AUTH PLAIN LOGIN 250-STARTTLS 250 HELP 
2015-06-23 06:58:46 CLIENT -> SERVER: STARTTLS 
2015-06-23 06:58:46 SERVER -> CLIENT: 220 TLS go ahead 
Warning: stream_socket_enable_crypto() [function.stream-socket-enable-crypto]: SSL: The operation completed successfully. in C:\xampp\htdocs\ehars\phpmailer\class.smtp.php on line 344
2015-06-23 06:58:46 SMTP Error: Could not connect to SMTP host. 
2015-06-23 06:58:46 CLIENT -> SERVER: QUIT 
Notice: fwrite() [function.fwrite]: send of 6 bytes failed with errno=10054 An existing connection was forcibly closed by the remote host. in C:\xampp\htdocs\ehars\phpmailer\class.smtp.php on line 937
2015-06-23 06:58:46 SERVER -> CLIENT: 
2015-06-23 06:58:46 SMTP ERROR: QUIT command failed: 
2015-06-23 06:58:46 Connection: closed 2015-06-23 06:58:46  SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Message could not be sent.Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

UPDATE :

Checked my phpinfo () and the ssl has been enabled.

来源:https://stackoverflow.com/questions/30997068/phpmailer-smtp-error-could-not-connect-to-smtp-host

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!