Php mailer 5.2.14没有';我不允许我发电子邮件,我';我用拉拉贡

Php mailer 5.2.14没有';我不允许我发电子邮件,我';我用拉拉贡,php,phpmailer,mailer,Php,Phpmailer,Mailer,我正在创建一个注册系统,必须发送电子邮件确认。我已经安装了laragon,我正在使用php mailer,版本5.2.14。phpmyadmin的设置很好,它接受用户的注册数据,但没有发送电子邮件 允许我创建用户并发送电子邮件的注册代码(位于function.php中)如下所示: function createuser($first_name, $last_name, $username, $email, $password) { global $url; $first_name

我正在创建一个注册系统,必须发送电子邮件确认。我已经安装了laragon,我正在使用php mailer,版本5.2.14。phpmyadmin的设置很好,它接受用户的注册数据,但没有发送电子邮件

允许我创建用户并发送电子邮件的注册代码(位于function.php中)如下所示:

 function createuser($first_name, $last_name, $username, $email, $password)
   {   

global $url;
$first_name = escape($first_name);
$last_name = escape($last_name);
$username = escape($username);
$email = escape($email);
$password = escape($password);
$password = password_hash($password);
$token = password_hash($username . microtime());
$sql = "INSERT INTO users(first_name,last_name,username,email,password,token,activition) ";
$sql .= "VALUES('$first_name','$last_name','$username','$email','$password','$token',0)";
confirm(query($sql));
//this is the message that is going to appear to user and it says to open the email where there's    the activation link
set_message('Per favore controlla la tua email o la tua cartella spam per vedere il link di   attivazione');
//this is the content of the email, that contains my email 
$subject = "Attivazione account";
$msg = "Clicca su questo link per attivare il tuo account
        $url/activate.php?email=$email&code=$token";
$headers = "From: caredda.sara@gmail.com";
send_email($email, $subject, $msg, $headers);
redirect('index.php');
}
//this is the function to send the email
function send_email($email, $subject, $msg, $headers)
{
return mail($email, $subject, $msg, $headers);
}
我创建了另一个文件,其中包含注册系统的html代码,该文件链接到function.php文件。在html代码之前,我复制粘贴了phpmailer代码并进行了自定义修改。这是代码:

<?php if(isset($_POST['sendmail'])) {
        require 'phpmailer/PHPMailerAutoload.php'; 

        $mail = new PHPMailer;

        // $mail->SMTPDebug = 4;                              // Enable verbose debug output

        $mail->isSMTP();                                      // Set mailer to use SMTP
        $mail->Host = 'smtp.gmail.com';                       // Specify main and backup SMTP servers
        $mail->SMTPAuth = true;                               // Enable SMTP authentication
        $mail->Username = 'caredda.sara@gmail.com';           // SMTP username
        $mail->Password = 'my_google_account_password';       // SMTP password
        $mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
        $mail->Port = 587;                                    // TCP port to connect to

        $mail->setFrom('caredda.sara@gmail.com', 'Sara Caredda');
        $mail->addAddress($_POST['email']);                   // Add a recipient

        $mail->addReplyTo('caredda.sara@gmail.com');
        // print_r($_FILES['file']); exit;
        for ($i=0; $i < count($_FILES['file']['tmp_name']) ; $i++) { 
            $mail->addAttachment($_FILES['file']['tmp_name'][$i], $_FILES['file']['name'][$i]);    // Optional name
        }
        $mail->isHTML(true);                                  // Set email format to HTML

        $mail->Subject = $_POST['subject'];
        $mail->Body    = '<div style="border:2px solid red;">Body del messaggio html<b>in bold!</b></div>';
        $mail->AltBody = $_POST['message'];

        if(!$mail->send()) {
            echo 'Il messaggio non è stato mandato.';
            echo 'Errore Mailer: ' . $mail->ErrorInfo;
        } else {
            echo 'Il messaggio è stato mandato';
        }
    }
 ?>


就这些。这段代码不发送任何电子邮件,我是一名学生,我正在努力了解原因。我整个晚上都在努力。我想,现在是寻求帮助的时候了。你能帮帮我吗?

我想是关于授权的问题。
您需要访问Google帐户的安全页面,并打开“不太安全的应用程序访问”的访问权限。

我这样做了,我忘记提到了,但我做到了。呃……没什么,我还在努力弄明白这里有什么问题