简体   繁体   English

SMTP邮件发送不起作用

[英]SMTP mail sending not working

I am using smtp to send email from my website, The code I have used is given below. 我使用smtp从我的网站发送电子邮件,我使用的代码如下。 It is showing error. 它显示错误。 not working. 不工作 I have enabled openssl in my website. 我在我的网站上启用了openssl。

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错误:无法进行身份验证。 SMTP connect() failed. SMTP connect()失败。

在此输入图像描述 follow this settings in you're gmail account https://www.formget.com/codeigniter-gmail-smtp/ 在您的Gmail帐户https://www.formget.com/codeigniter-gmail-smtp/中按照此设置操作

check with now username and password ..i've enabled it 现在检查用户名和密码..我已启用它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM