Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
171 views
in Technique[技术] by (71.8m points)

php - PHPMailer Mail Error - >SMTP connect()

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 = "[email protected]";
    $mail->Password = "mypass";
    $mail->SMTPSecure = "ssl";
    $mail->Host = "smtp.gmail.com";
    $mail->Port = "587";

    $mail->setFrom('[email protected]', 'your name');
    $mail->AddAddress('[email protected]', '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;
    }
    ?>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 = '[email protected]';
   $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';
 }
    ?>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...