首页 > 解决方案 > 在 wordpress 网站上使用 php mailer 提交邮件后重定向到空白页

问题描述

我已使用 php 邮件程序在我的网站上应用基于 HTML 的简历页面。一切都很好,直到我尝试在 wordpress 网站上做同样的事情。我已经上传了页面“application.php”、供应商文件夹(作曲家创建的文件夹)和 mail.php 文件,在 wordpress 中设置并尝试运行。当我单击提交按钮时,它会重定向到我在“操作”表单中设置的页面“mail.php”,该页面在技术上是空白的,但它包含用于发送邮件的代码。我试图用 header() 更改它的 mail.php,但无论我在 mail.php 中写什么,它仍然被重定向到 mail.php 并显示空白页。

                <form action="mail.php" method="post" enctype="multipart/form-data">
                    <div class="contact__msg m-auto" style="display: none">
                        <p>Twoja wiadomość została do nas pomyślnie wysłana</p>
                    </div>
                    <div class="row">
                        <div class="form-group col-6 m-auto mb-4">
                            <input type="text" name="name" class="m-auto" placeholder="imię *"  required id="">
                        </div>

                        <div class="form-group col-6 m-auto mb-4">
                            <input type="file" name="tfile" class="m-auto" id="fileToUpload" >
                        </div>
                        <div class="form-group col-4 m-auto">
                            <input class="btnContact" type="submit" class="m-auto"value="Upload Image" name="submit">
                        </div>
                        <div class="form-group col-4 m-auto">
                            <div class="g-recaptcha" class="m-auto" data-sitekey="mysitekey"></div>
                        </div>
                        <div class="col-md-12">
                            <div class="form-group">
                                <textarea name="message" class="form-control" style="display: none;"></textarea>
                            </div>
                        </div>
                    </div>
                </form>

请给我一些提示可能有什么问题或我没有考虑到什么。我也是 WordPress 和 PhP 的新用户,所以我可能不知道一些事情。

和mail.php

<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\SMTP;


if (isset($_POST['submit']))  { //Load Composer's autoloader
    require 'vendor/autoload.php';
    $mail = new PHPMailer(true);


//captcha
    $secretKey = 'xxx';
    $captcha = $_POST['g-recaptcha-response'];
    if (!$captcha) {
        echo '<p class="alert alert-warning m-auto">Please check recaptcha</p>';
        exit;
    }


    $ip = $_SERVER['REMOTE_ADDR'];
    $response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=" . $secretKey . "&response=" . $captcha . "&remoteip=" . $ip);
    $responseKeys = json_decode($response, true);
    //captcha
                            // Passing `true` enables exceptions
    if (intval($responseKeys["success"]) !== 1) {
        echo '<p class="alert alert-warning m-auto">Please check recaptcha</p>';
        exit;
    }

    else {

        try {
            $mail->isSMTP();

            $mail->Host = 'smtp.gmail.com';

            $mail->Port = 587;
            $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
            $mail->SMTPAuth = true;

            $mail->Username = 'mail@gmail.com';
            $mail->Password = 'pass';
//i am adding those lines to be sure that it uses the SMTP protocol even if i have the SMTP Mail Addon

            $mail->setFrom('mailto@gmail.com', 'Aplikant'); 
            $mail->addAddress('mail@gmail.com');         
            $mail->CharSet = "UTF-8"; // Polish lang

            $name = str_replace(array("\r", "\n"), array(" ", " "), strip_tags(trim($_POST["name"]))); // 

            $getFilename = $_FILES['tfile']['tmp_name']; 

            //Attachments
            $maxsize = 2 * 1024 * 1024; // 2 MB 
            $types = array('application/pdf'); // allowed mime-types 

            if (filesize($getFilename) < $maxsize && in_array(mime_content_type($getFilename), $types)) {
                $mail->addAttachment($getFilename, "CV-$name.pdf");  

            } else {
                echo '<p class="alert alert-warning m-auto"> Check size or extension</p>';
                exit;
            }


            $mail->isHTML(true);                 // Set email format to HTML
            $mail->Subject = 'CV Aplikanta';   /
            $mail->Body = 'Oto CV aplikanta';   
            $mail->AltBody = 'Oto CV aplikanta';  

            $mail->send();
            echo '<p class="alert alert-warning m-auto" >Mail was send</p>'; 
            exit;

        }
        catch (Exception $e) {
            echo '<p class="alert alert-warning m-auto" >Mail was <b>Not</b> send</p>', $mail->ErrorInfo;
            exit;

        }

    }
    header("Location: customAplikacja");
    exit;
}

标签: phpwordpressemailphpmailer

解决方案


推荐阅读