【问题标题】:PHPMailer not working?PHPMailer 不工作?
【发布时间】:2018-06-21 11:57:21
【问题描述】:

我的PHPMailer 脚本不适用于here 表单。 我正在使用 Gmail SMTP。 该表格没有附件选项,所以我禁用了它。 请注意,我已将 SMTP 登录信息(从电子邮件到电子邮件)替换为虚拟电子邮件,仅用于在 stackoverflow 上发布。 顺便说一句,它与 autoload.php 文件的绝对 url 有什么关系吗?

// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

//Load Composer's autoloader
require content_url('/phpmailer/vendor/autoload.php');

$mail = new PHPMailer(true);                              // Passing `true` enables exceptions
try {
    //Server settings
    $mail->SMTPDebug = 1;                                 // 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 = 'example@gmail.com';                 // SMTP username
    $mail->Password = 'secret';                           // SMTP password
    $mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 587;                                    // TCP port to connect to

    //Recipients
    $mail->setFrom('example2@gmail.com', 'example2');
    $mail->addAddress('example3@gmail.com');     // Add a recipient

    //Attachments
    // $mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
    // $mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name

    //Content
    $mail->isHTML(true);                                  // Set email format to HTML
    $mail->Subject = 'Application form submission';
    $mail->Body    = $message;
    $mail->AltBody = strip_tags($message);

    $mail->send();
    echo 'Message has been sent';
} catch (Exception $e) {
    echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}

谁能告诉我为什么它不起作用?

我收到以下错误:-

注意:未定义索引:/nas/content/live/financemi/wp-content/plugins/insert-php-code-sn-p/shortcode-handler.php(65) 中的income_checkbox : eval()'d 代码在第 495 行

警告:require(): https:// 包装器在服务器配置中被 /nas/content/live/financemi/wp-content/plugins/insert-php-code-sn-p/ 中的 allow_url_include=0 禁用shortcode-handler.php(65) : eval()'d 代码在第 5164 行

警告:需要(https://www.financemi.com.au/wp-content/phpmailer/vendor/autoload.php):无法打开流:在 /nas/content/live/financemi/wp-content/plugins/insert-php-code-sn-p/shortcode 中找不到合适的包装器-handler.php(65) : eval()'d 代码在第 5164 行

致命错误:require():在 / nas/content/live/financemi/wp-content/plugins/insert-php-code-sn-p/shortcode-handler.php(65) : eval()'d code on line 5164

【问题讨论】:

  • error reporting 添加到文件顶部测试时在您打开PHP标记之后,例如<?php error_reporting(E_ALL); ini_set('display_errors', 1);
  • @RiggsFolly 我添加了错误报告,我已经提到了上面的错误。请检查一下。
  • 大部分是与 PHPMailer 无关的 Wordpress 错误;只有致命错误才是相关的。

标签: php phpmailer


【解决方案1】:

您需要在本地 require 自动加载器,而不是通过 HTTP/HTTPS。 (因为通过 HTTP,您将是 requiring 脚本的输出,这将是空的,而不是它的代码。)

变化:

require 'https://www.financemi.com.au/wp-content/phpmailer/vendor/autoload.php';

到:

require __DIR__.'/../../../wp-content/phpmailer/vendor/autoload.php';

(更新以反映 PHP 脚本在 wp-content/plugins/insert-php-code-sn-p/ 目录中获取 eval()。)

【讨论】:

  • 它没有用,可能是因为它是 wordpress。那么对路径有什么想法吗?
  • 好的,所以我更正了路径并得到了错误,有问题,请检查一下?
  • 好吧,您将其更改为 content_url() 调用,这又会生成带有 HTTP/HTTPS 的 URL,因此您是正确的开始。使用require时是否显示任何错误消息,如我的回复所示?
  • 当我使用你显示的 require 时,我收到以下错误:-
  • 注意:未定义索引:/nas/content/live/financemi/wp-content/plugins/insert-php-code-sn-p/shortcode-handler.php(65) 中的income_checkbox:评估()'d 代码在第 493 行
猜你喜欢
  • 2014-03-14
  • 1970-01-01
  • 2012-05-21
  • 2014-08-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多