PHPMailer错误连接gmail's SMTP


PHPMailer error to connect in gmail's SMTP

我正在尝试使用gmail的smtp发送电子邮件,但我有错误。首先,我在github手册中有"类SMTP未找到"来安装PHPMalier,我发现我需要要求SMTP类"class. SMTP .php"。我有错误,所以我看到我需要要求"phpmailerautolload .php"而不是"class.PHPMailer.php"。现在,我有其他的错误。我累了!我很久以前就想解决这个问题了。查看正在发生的错误:

使用smtp.gmail.com发送电子邮件错误

我做了一个类来发送电子邮件,就像git中的例子:

<?php
    $txtName    = "Bruno";
    $txtAs    = "As";
    $txtEmail    = "Text mail";
    $txtMensage    = "Text Body";
    $mensageBody         = "<b>Name:</b> ".$txtName." <br><b>As:</b> ".$txtAs."<br><b>Message:</b> ".$txtMensage;
    require 'phpmailer/PHPMailerAutoload.php';
    require 'phpmailer/class.smtp.php';
    function smtpmailer($to, $from, $nameDes, $as, $body) {
        global $error;
        $mail = new PHPMailer();
        $mail->IsSMTP();
        $mail->SMTPDebug = 2;
        $mail->SMTPSecure = 'tls';
        $mail->Host = 'smtp.gmail.com';
        $mail->Port = 587;
        $mail->SMTPAuth = true;
        $mail->SMTPSecure = true;
        $mail->Username = 'mail@gmail.com';
        $mail->Password = 'pass';
        $mail->SetFrom($from, $nameDes);
        $mail->Subject = $as;
        $mail->Body = $body;
        $mail->AddAddress($to);
        $mail->IsHTML(true);
        if(!$mail->Send()) {
            $error = "<font color='red'><b>Mail error: </b></font>".$mail->ErrorInfo;
            return false;
        } else {
            $error = "<font color='blue'><b>Mensagem enviada com Sucesso!</b></font>";
            return true;
        }
    }
     if (smtpmailer('mail@gmail.com', 'mail@gmail.com', $txtName, $txtAs, $mensageBody)) {
         Header("location: sucesso.php");
     }
     if (!empty($error)) echo $error;
    ?>

我的项目树如下:

项目树

我已经尝试在gmail帐户中找到配置,并检查这些链接:PHPMailer无法连接到SMTP主机。phpmailer无法连接到SMTP

和更多…但什么也帮不了我。拜托,我需要帮助!

我发现了错误。我使用了使用phpMailer发送电子邮件的Locaweb的例子,但我添加SMTPSecure = 'tls';我得到了!

这篇文章帮助了我:SMTP错误:无法验证!在PHPMailer

这是关于Locaweb的phpMailer的帖子:(葡萄牙语)http://wiki.locaweb.com.br/pt-br/Enviar_e-mails_pelo_PHP_usando_o_PHPMailer

谢谢! !