使用gmail smtp服务器时我的电子邮件没有发送?

时间:2015-03-09 17:48:08

标签: email smtp gmail

我在我的网站上使用gmail smtp服务器在用户注册时发送电子邮件但目前我无法发送电子邮件所有信息都是正确的。我该如何解决这个问题?我正在使用php邮件程序

function send()
    {
    $mail          = new PHPMailer();
    $mail->CharSet = 'UTF-8';
    $mail->IsSMTP();
    $mail->SMTPAuth = true;
    $mail->Host     = 'ssl://smtp.gmail.com';
    $mail->Port     = 465;
    $mail->Username = 'example@gmail.com';
    $mail->Password = 'mypassword';
    $mail->From     = 'noreply@example.com';
    $mail->FromName = 'example';
    $mail->AddAddress($this->_tpl_vars['TO']);
    if (isset($this->_tpl_vars['CC']))
        {
        $cc = explode(';', $this->_tpl_vars['CC']);
        foreach ($cc as $c)
            if (!empty($c))
                $mail->AddCC($c);
        }
    $mail->AddReplyTo('noreply@example.com');
    $i = array();
    $i = 3;
    $mail->IsHTML(true);
    $mail->Subject = $this->_tpl_vars['SUBJECT'];
    $mail->Body    = $this->_tpl;
    @$mail->Send();
    }

我在我的Gmail帐户中看到一条消息,一个用户尝试使用我的ip server gmail阻止它。

谢谢。

1 个答案:

答案 0 :(得分:0)

您可以转到https://www.google.com/settings/security/lesssecureapps 并打开“访问不太安全的应用程序”

现在正确的方法:您可能需要检查https://developers.google.com/gmail/xoauth2_libraries有关如何使用Oauth2进行PHP示例的<{p}}

相关问题