PHPMailer不工作?
我的脚本无法用于表单。 我正在使用Gmail SMTP。 表单没有附件选项,因此我禁用了它。 请注意,我已将SMTP登录信息(从电子邮件到电子邮件)替换为虚拟电子邮件,仅用于在stackoverflow上发布。 顺便说一句,这可能与autoload.php文件的绝对url有关吗PHPMailer不工作?,php,phpmailer,Php,Phpmailer,我的脚本无法用于表单。 我正在使用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
// 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;
}
有人能告诉我为什么它不起作用吗
我收到以下错误:-
注意:第495行的/nas/content/live/financemi/wp content/plugins/insert php代码片段/shortcode handler.php(65):eval()d代码中的未定义索引:income_复选框 警告:require():https://wrapper在服务器配置中被/nas/content/live/financemi/wp content/plugins/insert php code snippet/shortcode handler.php(65):eval()第5164行代码中的allow_url_include=0禁用 警告:require():无法打开流:在第5164行的/nas/content/live/financemi/wp content/plugins/insert php代码段/shortcode handler.php(65):eval()d代码中找不到合适的包装器 致命错误:require():无法在/nas/content/live/financemi/wp content/plugins/insert php代码段/shortcode handler.php(65):eval()中打开所需的“”(include_path=':/usr/share/pear/php:/usr/share/php:/usr/share/pear')
您需要在本地而不是通过HTTP/HTTPS要求自动加载器。(因为通过HTTP,您将
需要脚本的输出,它将是空的,而不是它的代码。)
更改:
require 'https://www.financemi.com.au/wp-content/phpmailer/vendor/autoload.php';
致:
(更新以反映PHP脚本在wp content/plugins/insert PHP代码片段/目录中获取eval())在打开PHP标记后立即进行测试时添加到文件的顶部,例如@riggsfully我添加了错误报告,我已经提到了上面的错误。请你检查一下,大多数都是Wordpress错误,与PHPMailer没有任何关系;这只是一个致命的错误,它不起作用,可能是因为它是wordpress。对路径有什么想法吗?好的,我纠正了路径并得到了错误,如问题中所述,请检查一下好吗?您将其更改为content\u url()
call,这反过来会生成带有HTTP/HTTPS的url,所以您的起点是正确的。如我的回答所示,当您使用require
时是否显示任何错误消息?当我如您所示使用require时,我收到以下错误:-注意:未定义索引:income\u复选框位于/nas/content/live/financemi/wp content/plugins/insert php代码片段/shortcode handler.php(65):eval()'d代码第493行
require __DIR__.'/../../../wp-content/phpmailer/vendor/autoload.php';