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

时间:2016-07-30 10:00:01

标签: php smtp

我在我的服务器上使用此代码发送邮件,但没有正确回复

 <?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 = "contactform@abc.com";
        $mail->Password = "********";
        $mail->SetFrom("contactform@abc.com", '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 = 'vcv@outlook.com';
         $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... ";
           }
        }
    } 
    ?>

1 个答案:

答案 0 :(得分:0)

您似乎正在使用PHPMailer库发送邮件和以及在执行发送邮件请求的同时使用mail()函数。让我们更详细地讨论这个问题,这样你就会明白为什么会这样?

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

在IsSMTP();

之前添加此项
$mail = new PHPMailer;

USE

$mail->SMTPSecure = 'tls';

INSTEAD OF(SSL用于接收邮件而非发送)

$mail->SMTPSecure = 'ssl';

删除PHPmailer函数中使用的mail()函数,如果有效则尝试发送邮件,然后在PHPmailer函数结束后尝试实现mail()函数。

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

如果没有运气,请尝试以正确的格式添加整个代码以及表单,以便帮助您跟踪问题。