weixin_33716154 2019-07-02 20:45 采纳率: 0%
浏览 20

PHP:PHPMailer阻止其他人

I have simple code in PHP and PHP library PHPMailer where I have email.php where email is added to database only if is not already in database. When is or not there is messages for adding email to database and not adding. All this thing working with AJAX. All working good without require 'newuser.php';.

I added newuser.php file to else on the bottom which is using PHPMailer functions for sending emails. When Its in else on the bottom added require 'newuser.php'; in AJAX will be done fail branch not done branch which I want.

So all going well without require 'newuser.php'; and when its added to else on the bottom will be done fail branch not done branch so something going wrong there and i dont know what.

My email.php:

<?php
    if (empty($_POST['email'])) return http_response_code(404);

    $emaildb = mysqli_connect("localhost", "root", "root", "dbdbdbd");

    if(!$emaildb) {
        die("ERROR: Could not connect. " . mysqli_connect_error());
    }

    $email = mysqli_real_escape_string($emaildb, $_REQUEST['email']);

    $sql = "INSERT INTO emails (email)
            SELECT '$email'
            FROM DUAL
            WHERE NOT EXISTS 
                (SELECT 1
                FROM emails
                WHERE email = '$email')
            LIMIT 1";

    $result = mysqli_query($emaildb, $sql);

    header('Content-type: application/json');

    if(mysqli_insert_id($emaildb) == 0) {

        $dataDuplicate = array(
            "existing" => true, 
            "message" => "Váš e-mail už máme, nižšie si môžete stiahnúť potrebné dokumenty."
        );

        echo json_encode($dataDuplicate);
    } else {
        require 'newuser.php';

        $dataSuccess = array(
            "message" => "Úspech! Skontrolujte si prosím Vašu e-mailovú schránku."
        );
        echo json_encode($dataSuccess);

    }

    mysqli_close($emaildb);
?>

My newuser.php:

require 'config.php';
use PHPMailer\PHPMailer\PHPMailer;
date_default_timezone_set('Europe/Bratislava');
require 'vendor/autoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->CharSet = 'UTF-8';
$mail->Host = 'smtp.websupport.sk';
$mail->Port = 25;
$mail->SMTPAuth = true;
$mail->Username = 'test@true-blue.sk';
$mail->Password = 'pass';
$mail->setFrom('test@true-blue.sk', 'Fesky Vanka');
$mail->addReplyTo('test@true-blue.sk', 'Fesky Vanka');
$mail->addAddress('rebros.matus@gmail.com', 'John Doe');
$mail->Subject = 'Skuska skusiek';
$mail->msgHTML(file_get_contents('newmail.html'), __DIR__);
//$mail->AltBody = 'Na Váš email odteraz budu chodiť moje dokumenty.';
if (!$mail->send()) {
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message sent!';
}

My script.js:

(function($) {

    var form = $('#email-form');
    var message = $('#message');

    form.on('submit', function(event) {
        event.preventDefault();

        $.ajax({ 
            url: form.attr('action'), 
            type: 'POST', 
            data: form.serialize()
        }).done(function( res ) {
            console.log( res );
            form.hide();  
            $('#email-text').hide();

            if (res.existing) message.addClass('duplicate');
            else message.addClass('success');

            message.append(res.message);

            $.ajax({ 
                url: 'documents.php', 
                type: 'GET'
            }).done(function ( res ) {
                $('#docss').append(res);
                console.log( res );
              }).fail(function( res ) {
                $('#docss').append(res);
                console.error( res );
            });
        }).fail(function( res ) {
            console.log( res );

            alert('Prosím zadajte váš email');
        });

    });

}(jQuery));
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 c++的教材订购系统的订购模块显示运行不出来
    • ¥15 Coze智能助手搭建过程中的问题请教
    • ¥15 12864只亮屏 不显示汉字
    • ¥20 三极管1000倍放大电路
    • ¥15 vscode报错如何解决
    • ¥15 前端vue CryptoJS Aes CBC加密后端java解密
    • ¥15 python随机森林对两个excel表格读取,shap报错
    • ¥15 基于STM32心率血氧监测(OLED显示)相关代码运行成功后烧录成功OLED显示屏不显示的原因是什么
    • ¥100 X轴为分离变量(因子变量),如何控制X轴每个分类变量的长度。
    • ¥30 求给定范围的全体素数p的(p-2)/p的连乘积值