我的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-snippet/shortcode-handler.php(65)中的income_checkbox:eval()的代码行495
警告:require():https://包装在服务器配置中被/ nas / content / live / financemi / wp-content / plugins / insert-php-code-snippet / shortcode-中的allow_url_include = 0禁用handler.php(65):eval()在第5164行上的代码
警告:require(https://www.financemi.com.au/wp-content/phpmailer/vendor/autoload.php):无法打开流:在/ nas / content / live / financemi / wp-content / plugins / insert-php-code-snippet / shortcode中找不到合适的包装器-handler.php(65):eval()在第5164行上的代码
致命错误:require():无法打开所需的'https://www.financemi.com.au/wp-content/phpmailer/vendor/autoload.php'(include_path ='。:/ usr / share / pear / php:/ usr / share / php:/ usr / share / pear')在/nas/content/live/financemi/wp-content/plugins/insert-php-code-snippet/shortcode-handler.php(65)中:eval()在第5164行上的代码
答案 0 :(得分:1)
您需要在本地require
而不是通过HTTP / HTTPS来requiring
。 (因为通过HTTP,您将是require 'https://www.financemi.com.au/wp-content/phpmailer/vendor/autoload.php';
脚本的输出,它将为空,而不是其代码。)
更改:
require __DIR__.'/../../../wp-content/phpmailer/vendor/autoload.php';
收件人:
DIV
(已更新,以反映PHP脚本在wp-content / plugins / insert-php-code-snippet /目录中获得了eval()。)