du4822 2016-07-30 10:00
浏览 399

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

I am using this code on my server for sending mail, but not respond properly

 <?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 
";
        $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条回答 默认 最新

  • dpxyfa4718 2016-07-30 11:45
    关注

    It seems you are using PHPMailer library to send out mails & along with that using mail() function at the same time while executing request to send mail. Let's discuss this more in detail so you will come to know why is it happening?

    You haven't shown all of your code in correct format and even the form is missing to trace the issue. However there are some points i think could be a problem and those are as follows

    Add this before IsSMTP();

    $mail = new PHPMailer;
    

    USE

    $mail->SMTPSecure = 'tls';
    

    INSTEAD OF (SSL is used for Receiving mail not for sending)

    $mail->SMTPSecure = 'ssl';
    

    Remove the mail() function used within your PHPmailer function and try sending mail if it works then try implementing mail() function once the PHPmailer function ends.

    Quick Note: You can add multiple PHPmailer function at the same time.

    If ended up in no luck, try adding entire code in proper format along with form so will help you to track the issue.

    评论

报告相同问题?

悬赏问题

  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多