【发布时间】: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 错误;只有致命错误才是相关的。