PHPMailer 根本不工作

标签 php phpmailer

我正在尝试配置 PHPMailer 我上传了 1 个文件,它是 class.phpmailer.php 并创建了另一个包含以下内容的 php 文件:

<?php
require('class.phpmailer.php');
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
$mail->Host = "smtp.gmail.com";
$mail->Port = 465; // or 587
$mail->IsHTML(true);
$mail->Username = "myemail@gmail.com";
$mail->Password = "mypassword";
$mail->SetFrom("the same email address");
$mail->Subject = "Test";
$mail->Body = "hello";
$mail->AddAddress("the same email address");
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent";
}
?>

我什么也没有得到,不是成功消息也不是失败消息。 http://www.mawk3y.net/mailtest/test.php

最佳答案

现在所有的答案都过时了。大多数当前版本(截至 2018 年 2 月)不再具有自动加载功能,PHPMailer 应初始化如下:

<?php

  include_once(FCPATH.'PHPMailer/src/PHPMailer.php');
  include_once(FCPATH.'PHPMailer/src/SMTP.php');
  include_once(FCPATH.'PHPMailer/src/Exception.php');

    $msj="My complete message";
    $mail = new PHPMailer\PHPMailer\PHPMailer();
    $mail->IsSMTP(); // enable SMTP
    $mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
    //authentication SMTP enabled
    $mail->SMTPAuth = true; 
    $mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
    $mail->Host = "smtp.gmail.com";
    //indico el puerto que usa Gmail 465 or 587
    $mail->Port = 465; 
    $mail->Username = "xxxxxx";
    $mail->Password = "xxxx";
    $mail->SetFrom("xxxxxx@xxxxx.com","Name");
    $mail->AddReplyTo("xxx@xxx.com","Name Replay");
    $mail->Subject = "Test";
    $mail->MsgHTML($msj);
    $mail->AddAddress("xxxxxx@xxxxx.com");

 if(!$mail->Send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
 } else {
    echo "Message has been sent";
 }
?>

关于PHPMailer 根本不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20000869/

相关文章:

php - 如何使用 phpmailer 在带有 html 的邮件中正确添加图像?

php - 使用 PHPMailer 通过 SMTP 发送电子邮件

用于 Azure AD 租户/用户计数的 PHP Api

javascript - PHP POST 变量值

php - {% %}在html中是什么意思

css - 单元格填充在 Gmail 中准确,但在 Microsoft Outlook 中不准确

php - 返回目录尝试时,导航菜单 A Href 不起作用?

php - Laravel 通过关系搜索

php - 如何向两个不同的用户发送两个不同的消息phpmailer

php - 如何创建雅虎 smtp 服务器的套接字?