2016-09-20 144 views
-2

我想发送电子邮件使用gmail的smtp,但我有erros。首先,根据github手册安装PHPMalier,我发现“class SMTP not found”,我发现我需要smtp类“class.smtp.php”。我还有错,所以我看到我需要“PHPMailerAutoLoad.php”而不是“class.PHPMailer.php”。现在,我有其他的错误。我累了!我正在尝试解决这个问题。看看正在发生的错误:PHPMailer错误连接在Gmail的SMTP

Errors to send email using 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 = '[email protected]'; 
     $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('[email protected]', '[email protected]', $txtName, $txtAs, $mensageBody)) { 
     Header("location: sucesso.php"); 
    } 
    if (!empty($error)) echo $error; 

    ?> 

我的项目树看看这个:

Project Tree

我已经尝试在gmail帐户中查找配置,并检查以下链接: PHPMailer "Could not connect to SMTP host." phpmailer Could not connect to SMTP

还有更多...但没有任何帮助。请,我需要帮助!

+1

这在PHPMailer麻烦指南中提到了错误信息(以及其他问题)的链接。阅读。另外,如果您已经加载自动加载器,则不需要手动加载SMTP类,并且如果您使用的是Composer,则不需要手动加载任何内容。 – Synchro

+0

好的,我删除了,但错误仍然存​​在。我已经阅读了故障排除,并且我已经尝试了很多我在那里找到的东西,但没有解决方案。 –

+0

那么当你尝试telnet时发生了什么? – Synchro

回答

相关问题