0
votes

I am using gmail smtp server on my website to send email when users register but currently I can not send emails all information is correct. How can I fix this issue? I am using php mailer

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 = '[email protected]';
    $mail->Password = 'mypassword';
    $mail->From     = '[email protected]';
    $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('[email protected]');
    $i = array();
    $i = 3;
    $mail->IsHTML(true);
    $mail->Subject = $this->_tpl_vars['SUBJECT'];
    $mail->Body    = $this->_tpl;
    @$mail->Send();
    }

I see message in my gmail account one user try login with my ip server gmail block it.

Thank you.

1

1 Answers

0
votes

You can go to https://www.google.com/settings/security/lesssecureapps and turn on "Access for less secure apps"

The proper way now: you may want to check https://developers.google.com/gmail/xoauth2_libraries for PHP examples on how to do it using Oauth2