当我们添加 SMTP 服务器时,网站会持续加载

问题描述 投票:0回答:1

我创建了一个 php 文件,在该文件中我向一位进行捐赠的用户发送电子邮件。 (捐款只是一个例子)

当用户提交捐款并填写表格时,网站就会持续加载。甚至没有显示错误。

但它没有显示任何电子邮件,甚至没有错误,但网站正在持续加载。

这是我的代码:

<?php
require_once($_SERVER["DOCUMENT_ROOT"] . "/wp-load.php");
require_once($_SERVER["DOCUMENT_ROOT"] . "/wp-content/plugins/project-funders/assets/smtp/PHPMailerAutoload.php");

global $wpdb;
$settingsTable = $wpdb->prefix . "flight_funders_settings";
$settings = $wpdb->get_results(
    "SELECT * FROM $settingsTable"
);

$emails = [];
$flightId = $_POST['flight_id'];
$prayerTable = $wpdb->prefix . "flight_funders_prayer_donations";
$moneyTable = $wpdb->prefix . "flight_funders_money_donations";
$prayers = $wpdb->get_results(
    "SELECT * FROM $prayerTable WHERE `flight_id`= $flightId"
);
$moneys = $wpdb->get_results(
    "SELECT * FROM $moneyTable WHERE `flight_id`= $flightId"
);
foreach($prayers as $prayer){
    $emails[] = $prayer->donator_email;
}

foreach($moneys as $money){
    $emails[] = $money->donator_email;
}

unset($_POST["flight_id"]);
$emailDatas = [];
foreach($_POST as $emailData){
    $emailDatas[] = $emailData;
}

$mail = new PHPMailer(); 
$mail->IsSMTP(); 
$mail->SMTPAuth = true; 
$mail->SMTPSecure = 'tls'; 
$mail->Host = $settings[7]->settings_value;
$mail->Port = $settings[8]->settings_value; 
$mail->IsHTML(true);
$mail->CharSet = 'UTF-8';
$mail->Username = $settings[9]->settings_value;
$mail->Password = $settings[10]->settings_value;
$mail->SetFrom($settings[9]->settings_value);
$mail->Subject = $emailDatas[0];
$mail->Body = $emailDatas[1];
$mail->addBCC($settings[9]->settings_value);
foreach($emails as $email){
    $mail->addBCC($email);
}
if(!$mail->Send()){
    echo "Sorry";
}
else{
    $flightTable = $wpdb->prefix . "flight_funders_flights";
    $flights = $wpdb->get_results(
        "SELECT * FROM $flightTable WHERE `flight_id`=$flightId"
    )[0];
    $flight_title = $flights->flight_title;
    $notificationTable = $wpdb->prefix . "flight_funders_notifications";
    $insertNotification = $wpdb->query(
        "INSERT INTO $notificationTable (`flight_title`, `notification_subject`, `notification_message`) VALUES ('$flight_title','$emailDatas[0]','$emailDatas[1]')"
    );
    echo "Sent";
}
?>

我该如何解决这个问题?

谢谢

php smtp phpmailer smtpclient
1个回答
0
投票

请检查您的所有更改并确保所有选项均已正确选择。我也遇到了同样的问题,忘记开启SSL加密,不过幸运的是,问题解决了。 在此输入图片描述

© www.soinside.com 2019 - 2024. All rights reserved.