如何将PHPmailer配置为本地主机的sendmail和Gmail?

如何将PHPmailer配置为本地主机的sendmail和Gmail?,php,sendmail,phpmailer,Php,Sendmail,Phpmailer,我已经找了一个多星期的答案了。我被这个问题困住了。我已下载sendmail文件夹并对其进行了配置。是的,上面写的是真实的信息,但实际上并没有发送到邮件中。所以我决定把PHPmailer作为我在一些网站上读到的东西。我下载了PHPmailer并对其进行了配置。当我运行它时,有一个错误。致命错误:在第1197行的C:\wamp\www\Project\PHPMailer\Class.PHPMailer.php中找不到类“SMTP”。 我还阅读了一些解决方案,将代码粘贴到第104行(连接到smtp服务

我已经找了一个多星期的答案了。我被这个问题困住了。我已下载sendmail文件夹并对其进行了配置。是的,上面写的是真实的信息,但实际上并没有发送到邮件中。所以我决定把PHPmailer作为我在一些网站上读到的东西。我下载了PHPmailer并对其进行了配置。当我运行它时,有一个错误。致命错误:在第1197行的C:\wamp\www\Project\PHPMailer\Class.PHPMailer.php中找不到类“SMTP”。 我还阅读了一些解决方案,将代码粘贴到第104行(连接到smtp服务器)之前。但是我的104线看起来像这样。 公共$CRLF=“\r\n”


你们能帮帮我吗。我被困在这里。

你有最新的带自动装填器的PHPMailer吗

请参阅,因为邮件程序不再从PHPMailer类中调用SMTP类。这是一个痛苦,当我更新为调用邮件直接产生了这个错误

同时打开PHPMailers调试反馈,看看它说了什么

下面是我在很多项目中使用的sendMail()方法。它使用PHPMailer

    function sendMail($toAddress, $subject, $body, $AttachmentFilePath) {
    $mail = new PHPMailer();

    $mail->IsSMTP ();
    $mail->CharSet = 'UTF-8';
    // nable SMTP debugging
    // 0 = off (for production use)
    // 1 = client messages
    // 2 = client and server messages
    $mail->SMTPDebug = 0; // To prevent any outpur
    // Ask for HTML-friendly debug output
    $mail->Debugoutput = 'html';
    // Get the hostname of the mail server
    $mail->Host = 'smtp.gmail.com';
    // Get the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
    $mail->Port = 587;
    // Get the encryption system to use - ssl (deprecated) or tls
    $mail->SMTPSecure = 'tls';
    // Whether to use SMTP authentication
    $mail->SMTPAuth = TRUE;

    // Username to use for SMTP authentication - use full email address for gmail
    $mail->Username = "your.email@gmail.com";
    // Password to use for SMTP authentication. Specific to the Lead Qualifier Tool
    $mail->Password = "YourPassWordHere";

    // Set who the message is to be sent from
    $mail->SetFrom ( 'your.email@gmail.com', 'Your Name' );

    // To Address
    $mail->AddAddress ( $toAddress, $toAddress );

    $mail->Subject = $subject;

    $mail->Body = $body;
    $mail->AltBody = $body;

    // Add attachment
    if ($AttachmentFilePath != NULL)
        $mail->AddAttachment ( $AttachmentFilePath );

    if (! $mail->Send ()) {
        echo "<br />Error while sending e-mail: " . $mail->ErrorInfo;
    } else {
        // echo "Message sent!";
    }
}
函数sendMail($toAddress、$subject、$body、$AttachmentFilePath){
$mail=new PHPMailer();
$mail->IsSMTP();
$mail->CharSet='UTF-8';
//启用SMTP调试
//0=关闭(用于生产使用)
//1=客户端消息
//2=客户端和服务器消息
$mail->SMTPDebug=0;//防止任何输出
//请求HTML友好的调试输出
$mail->Debugoutput='html';
//获取邮件服务器的主机名
$mail->Host='smtp.gmail.com';
//获取SMTP端口号-587,用于已验证的TLS,也称为RFC4409 SMTP提交
$mail->Port=587;
//让加密系统使用-ssl(已弃用)或tls
$mail->SMTPSecure='tls';
//是否使用SMTP身份验证
$mail->SMTPAuth=TRUE;
//用于SMTP身份验证的用户名-使用gmail的完整电子邮件地址
$mail->Username=“您的邮件。email@gmail.com";
//用于SMTP身份验证的密码。特定于Lead限定符工具
$mail->Password=“YourPassWordHere”;
//设置要从谁发送消息
$mail->SetFrom('your。email@gmail.com‘你的名字’;
//解决
$mail->AddAddress($toAddress,$toAddress);
$mail->Subject=$Subject;
$mail->Body=$Body;
$mail->AltBody=$body;
//添加附件
如果($AttachmentFilePath!=NULL)
$mail->AddAttachment($AttachmentFilePath);
如果(!$mail->Send()){
回显“
发送电子邮件时出错:“..mail->ErrorInfo; }否则{ //回显“已发送消息!”; } }
希望有帮助!:-)


此外,由于您使用的是GMail,请确保您创建了ASP(应用程序特定密码),并在此处使用它,而不是您的真实密码。

调试代码所指的是什么?PHPMailer有一个调试功能,它提供了更多的线索吗?您只需要按照提供的任何示例进行操作;您需要使用自动加载器或自己加载SMTP类以避免此问题。@DaniloEscapa您能告诉我您面临的错误是什么吗?请尝试在$body参数中传递一些内容。您应该在收件人的收件箱中看到它。邮件未发送PHPMailer错误:以下发件人地址失败:verbz95@gmail.com:在未连接的情况下调用Mail()。让我们在聊天中继续此操作。让我们在此处继续=>
    function sendMail($toAddress, $subject, $body, $AttachmentFilePath) {
    $mail = new PHPMailer();

    $mail->IsSMTP ();
    $mail->CharSet = 'UTF-8';
    // nable SMTP debugging
    // 0 = off (for production use)
    // 1 = client messages
    // 2 = client and server messages
    $mail->SMTPDebug = 0; // To prevent any outpur
    // Ask for HTML-friendly debug output
    $mail->Debugoutput = 'html';
    // Get the hostname of the mail server
    $mail->Host = 'smtp.gmail.com';
    // Get the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
    $mail->Port = 587;
    // Get the encryption system to use - ssl (deprecated) or tls
    $mail->SMTPSecure = 'tls';
    // Whether to use SMTP authentication
    $mail->SMTPAuth = TRUE;

    // Username to use for SMTP authentication - use full email address for gmail
    $mail->Username = "your.email@gmail.com";
    // Password to use for SMTP authentication. Specific to the Lead Qualifier Tool
    $mail->Password = "YourPassWordHere";

    // Set who the message is to be sent from
    $mail->SetFrom ( 'your.email@gmail.com', 'Your Name' );

    // To Address
    $mail->AddAddress ( $toAddress, $toAddress );

    $mail->Subject = $subject;

    $mail->Body = $body;
    $mail->AltBody = $body;

    // Add attachment
    if ($AttachmentFilePath != NULL)
        $mail->AddAttachment ( $AttachmentFilePath );

    if (! $mail->Send ()) {
        echo "<br />Error while sending e-mail: " . $mail->ErrorInfo;
    } else {
        // echo "Message sent!";
    }
}