简体   繁体   English

PHPMailer无法正常工作?

[英]PHPMailer not working?

My PHPMailer script is not working for the form here . 我的PHPMailer脚本不适用于此处的表单。 I am using Gmail SMTP. 我正在使用Gmail SMTP。 The form does not have attachment option so i disabled it. 该表格没有附件选项,所以我禁用了它。 Please note I have replaced SMTP login info, from email and to email with dummy emails only for the purpose of posting on stackoverflow. 请注意,我已将SMTP登录信息(从电子邮件和电子邮件替换为虚拟电子邮件)仅用于在stackoverflow上发布。 BTW, could it have anything to do with the absolute url to the autoload.php file? 顺便说一句,它与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;
}

Can anyone tell me why it isn't working? 谁能告诉我为什么它不起作用?

I am getting the following errors:- 我收到以下错误:

Notice: Undefined index: income_checkbox in /nas/content/live/financemi/wp-content/plugins/insert-php-code-snippet/shortcode-handler.php(65) : eval()'d code on line 495 注意:未定义的索引:/nas/content/live/financemi/wp-content/plugins/insert-php-code-snippet/shortcode-handler.php(65)中的income_checkbox:第495行的eval()代码

Warning: require(): https:// wrapper is disabled in the server configuration by allow_url_include=0 in /nas/content/live/financemi/wp-content/plugins/insert-php-code-snippet/shortcode-handler.php(65) : eval()'d code on line 5164 警告:require():在服务器配置中,通过/nas/content/live/financemi/wp-content/plugins/insert-php-code-snippet/shortcode-handler.php中的allow_url_include = 0禁用https://包装器(65):第5164行的eval()代码

Warning: require( https://www.financemi.com.au/wp-content/phpmailer/vendor/autoload.php ): failed to open stream: no suitable wrapper could be found in /nas/content/live/financemi/wp-content/plugins/insert-php-code-snippet/shortcode-handler.php(65) : eval()'d code on line 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行上的代码

Fatal error: require(): Failed opening required ' https://www.financemi.com.au/wp-content/phpmailer/vendor/autoload.php ' (include_path='.:/usr/share/pear/php:/usr/share/php:/usr/share/pear') in /nas/content/live/financemi/wp-content/plugins/insert-php-code-snippet/shortcode-handler.php(65) : eval()'d code on line 5164 致命错误:require():无法打开所需的内容' https://www.financemi.com.au/wp-content/phpmailer/vendor/autoload.php'(include_path ='。:/ usr / share / pear / php: /nas/content/live/financemi/wp-content/plugins/insert-php-code-snippet/shortcode-handler.php(65)中的/ usr / share / php:/ usr / share / pear'):eval( )第5164行的代码

You need to require the autoloader locally, not via HTTP/HTTPS. 您需要在本地而不是通过HTTP / HTTPS require自动加载器。 (Because via HTTP you would be requiring script's output, which would be empty, not its code.) (因为通过HTTP,您将requiring脚本的输出,该输出为空,而不是其代码。)

Change: 更改:

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

to: 至:

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

(Updated to reflect that PHP script gets eval()'d inside wp-content/plugins/insert-php-code-snippet/ directory.) (更新以反映PHP脚本在wp-content / plugins / insert-php-code-snippet /目录中获得了eval()。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM