SMTP邮件发送不起作用

I am using smtp to send email from my website, The code I have used is given below. It is showing error. not working. I have enabled openssl in my website.

require 'phpmailer/PHPMailerAutoload.php';
 define('GUSER', 'test@gmail.com'); // GMail username
define('GPWD', 'test11111'); // GMail password
$to='test11@gmail.com';
$body='hi';
$subject='request';
$from=GUSER;
$from_name='Support';
    $mail = new PHPMailer();  // create a new object
    $mail->IsSMTP(); // enable SMTP
    $mail->SMTPDebug = 1;  // debugging: 1 = errors and messages, 2 = messages only
    $mail->SMTPAuth = true;  // authentication enabled
    $mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
    //$mail->SMTPSecure = 'tls';
    $mail->Host = 'smtp.gmail.com';
    $mail->Port = 465;
    //$mail->Port = 587; 
    $mail->Username = 'test@gmail.com';
 $mail->Password = 'test11111';            
    $mail->SetFrom($from, $from_name);
    $mail->isHTML(false);
    $mail->Subject = $subject;
    $mail->Body = $body;
    $mail->AddAddress($to,'test');

echo !extension_loaded('openssl')?"Not Available":"Available";


    if(!$mail->Send()) {

        echo $error = 'Mail error: '.$mail->ErrorInfo; 
        //return false;
    } else {

        echo $error = 'Message sent!';
        //return true;
    }

showing error SMTP Error: Could not authenticate. SMTP connect() failed.

查看全部
dss087358
dss087358
2016/06/28 07:05
  • smtp
  • php
  • email
  • authentication
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

1个回复