dongqiang8474 2016-09-12 07:31
浏览 135
已采纳

PHPMailer邮件错误 - > SMTP连接()

I don't know why I get this error PHPMailer Mail Error - >SMTP connect(). How can I solve it? I don't have any idea how can I do I need exactly explications, I'm new with PHP

<?php
    require '../plugins/phpmailer/PHPMailerAutoload.php';
    $mail = new PHPMailer();
    $mail->CharSet = "utf-8";
    $mail->IsSMTP();
    $mail->SMTPDebug = 1;
    $mail->SMTPAuth = true;
    $mail->Username = "myemail@gmail.com";
    $mail->Password = "mypass";
    $mail->SMTPSecure = "ssl";
    $mail->Host = "smtp.gmail.com";
    $mail->Port = "587";

    $mail->setFrom('your_gmail@gmail.com', 'your name');
    $mail->AddAddress('to_mail@mail.com', 'receivers name');

    $mail->Subject = 'using PHPMailer';
    $mail->IsHTML(true);
    $mail->Body = 'Hi there ,
                            <br />
                            this mail was sent using PHPMailer...
                            <br />
                            cheers... :)';

    if ($mail->Send()) {
        echo "Message was Successfully Send :)";
    } else {
        echo "Mail Error - >" . $mail->ErrorInfo;
    }
    ?>
  • 写回答

2条回答 默认 最新

  • dsdtszi0520538 2016-09-12 08:13
    关注

    Error due to SMTP connection failed.So, Check your configuration first, you can check by comment the line $mail->IsSMTP();

    // $mail->IsSMTP();
    

    See below is working demo :

      <?php
       require 'phpmailer.php';
       require 'smtp.php';
       $mail = new PHPMailer;
      //$mail->IsSMTP(); // telling the class to use SMTP
       $mail->Host       = "smtp.gmail.com"; // SMTP server
       $mail->SMTPDebug  = 1;                     // enables SMTP debug information (for testing)
                                           // 1 = errors and messages
                                           // 2 = messages only
       $mail->SMTPAuth   = true;                  // enable SMTP authentication
       $mail->Host       = "smtp.gmail.com"; // sets the SMTP server
       $mail->Port       = 465;                    // set the SMTP port for the GMAIL server
       $mail->Username   = GMAIL EMAIL ID; // SMTP account username
       $mail->Password   = GMAIL PASSWORD;        // SMTP account password
       $mail->SMTPSecure = 'ssl';
    
    
       $mail->From = 'from@example.com';
       $mail->FromName = 'Mailer';
       $mail->addAddress('MAIL ID to whom you eant to send');               // Name is optional
    
      $mail->addCC('CC EMAIL ID');
      $mail->addBCC('BCC EMAIL ID');
      $mail->WordWrap = 50;                                 // Set word wrap to    50 characters
    
      $mail->Subject = 'Here is the subject';
      $mail->Body    = 'MESSAGE';
      $mail->AltBody = 'This is the body in plain text for non-HTML mail  clients';
    
      if(!$mail->send()) {
      echo 'Message could not be sent.';
      echo 'Mailer Error: ' . $mail->ErrorInfo;
      } else {
      echo 'Message has been sent';
     }
        ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵