SMTP - >错误:无法连接到服务器:连接被拒绝(111)使用Zoho邮件

问题描述:

我用我的发送邮件服务器上的代码,但没有正确响应SMTP - >错误:无法连接到服务器:连接被拒绝(111)使用Zoho邮件

<?php 
    function smtpmailer($to, $subject, $body) 
    { 
     require_once('phpmailer/class.phpmailer.php'); 
     $mail = new PHPMailer(); // create a new object 
     $mail->IsSMTP(); // enable SMTP 
     $mail->SMTPDebug = 1; 
     $mail->SMTPAuth = true; 
     $mail->SMTPSecure = 'ssl'; 
     $mail->Host = 'smtp.zoho.com'; 
     $mail->Port = 587; 
     $mail->Username = "[email protected]"; 
     $mail->Password = "********"; 
     $mail->SetFrom("[email protected]", 'af'); 
     $mail->Subject = $subject; 
     $mail->Body = $body; 
     $mail->isHTML(true); 
     $mail->AddAddress($to); 
     $mail->headers = "Content-type: text/html; charset=utf-8 \r\n"; 
     $mail->headers = "Content-type: image"; 

     if(!$mail->Send()) { 
      $error = 'Mail error: '.$mail->ErrorInfo; 
       echo $error; 
      $error_no = 0; 

     } else {  
      $error_no = 1;      
     } 
     return $error_no; 
    } 

    if(isset($_POST['Submit'])) 
    { 
     $name = $_POST['name']; 
     $email=$_POST['email'];  
     $msg = $_POST['comment']; 
     $error = $nameErr = $emailErr = $msgErr = ""; 
     if(empty($name) && empty($email) && empty($msg)) 
     { 
     $error ="please fill all fields"; 
     } 
     else 
     { 
     if($name == "") 
     { 
      $nameErr = "Please enter your name"; 
     } 
     else 
     { 
      if(!preg_match("/^[a-zA-Z ]*$/",$_POST['name'])) 
      { 
      $nameErr = "only letters and white spaces are allowed"; 

      } 
     } 
     if($email == "") 
     { 
      $emailErr = "please enter your email"; 
     } 
     else 
      { 
      if(!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) 
      { 
       $emailErr = "Invalid Email Id"; 
       } 
      } 
     } 
     if(empty($error) && empty($nameErr) && empty($emailErr) && empty($msgErr)) 
     { 
      $message = ''; 
      $message .= ' 
      <p>Hello,</p> 
      <h4>We have recicved new contact request. Follwoing are detials. </h4> 
       <table border=0>   
        <tr><td>Name -- </td><td>'.$name.'</td></tr> 
        <tr><td>Email ID -- </td><td>'.$email.'</td></tr> 
        <tr><td>Message -- </td><td>'.$msg.'</td></tr> 
       </table> 
      <p>Reagrds, <br/>Flxpert Team</p>'; 
     $to = '[email protected]'; 
     $sub = 'New contact request has logged.';   
     $to1=$email; 
     $subject1="Contact Successfull."; 
     $msg1 = ''; 
     $msg1 = '<p>Hello '.ucfirst($name).',</p> 
        <table border=0> 
        <tr> 
         <td>Your contact request has successfully submitted. We will contact you as soon as possiable.</td> 
        </tr>   
       </table> 
       <p>Reagrds, <br/>Flxpert Team</p>'; 

     smtpmailer($to, $sub, $message); 
      if(smtpmailer($to1, $subject1, $msg1)){ 
      $success="Your contact request has successfully submitted. We will contact you as soon as possiable. "; 
      } else{ 
      $error="Something went wrong... "; 
      } 
     } 
    } 
    ?> 
+0

尝试使您的代码更具可读性。你确定你的密码是正确的吗? –

+0

它看起来像你的代码没有公布完整的代码。请提供完整的代码与合适的犯人 –

看来你正在使用PHPMailer库发送邮件&以及在执行请求发送邮件的同时使用mail()函数。让我们更详细地讨论这个问题,这样你就会知道为什么会发生这种情况?

您没有以正确的格式显示所有的代码,甚至缺少表单来跟踪问题。但有一些我认为可能是一个问题,如下所示:

IsSMTP();

$mail = new PHPMailer; 

使用

$mail->SMTPSecure = 'tls'; 

INSTEAD OF(SSL用于接收邮件没有发送)

$mail->SMTPSecure = 'ssl'; 

删除您PHPMailer的功能中使用的mail()函数,并尝试发送邮件如果它工作,那么在PHPmailer函数结束后尝试实现mail()函数。

快速提示:您可以同时添加多个PHPmailer功能。

如果不幸运,请尝试以适当格式添加整个代码以及表单,这样可以帮助您跟踪问题。