AJAX电子邮件输入没有传递给php wp_mail脚本

时间:2017-02-25 05:20:05

标签: javascript php ajax email

我正在通过AJAX向php邮件程序发送电子邮件输入(使用wp_mail)。将电子邮件解压缩到wp_mail时,一切正常。当将电子邮件硬编码到ajax电子邮件变量中时,它不会通过,因此AJAX端有问题。

这是我的PHP / HTML代码:

function pdfDownloadShortcode($atts, $content = "")
{
    $atts = shortcode_atts(array(
        'imageurl' => '',
        'downloadurl' => '',
        'subject' => '',
        'class' => ''
    ), $atts, 'pdfdownload');

    return "<div id='pdfdownload' class='{$atts['class']}'>
                <div id='pdfdownload_container'>
                    <div id='pdfdownload_img'><img class='nopin' data-pin-nopin='any' src='{$atts['imageurl']}'></div>
                    <div id='pdfdownload_content'>
                        <form id='pdfdownload_form' class='signin'>
                            <input type='hidden' id='pdfdownload_downloadurl' name='downloadurl' value='{$atts['downloadurl']}'>
                            <input type='hidden' id='pdfdownload_subject' name='subject' value='{$atts['subject']}'>
                            <div>{$content}</div>
                            <div>
                                <input id='pdfdownload_email' class='pdfdownload_input' type='email' name='ne' data-placeholder='Enter your email...' placeholder='Enter your email...'>
                            </div>
                            <div>
                                <button id='pdfdownload_button' class='pdfdownload_button' type='submit'>Download it Now!</button>
                            </div>
                            <div style='padding: 5px 0 10px 0;'>
                                <input id='listvalue' name='nl[]' type='hidden' value='2' />
                                <input id='subscribering' checked='checked' name='subscribering' type='checkbox' value='yes' />
                                <span style='color: #2e2e2e; font-size: 12px'>Subscribe?</span>
                            </div>
                        </form>
                    </div>
                </div>
                <div id='pdfdownload_processing' style='display: none;'></div>
                <div id='pdfdownload_thankyou' style='display: none;'>Thank you!</div>
            </div>";

    // return "foo = {$atts['foo']}";
}

add_shortcode('pdfdownload', 'pdfDownloadShortcode');

function pdfDownloadSend(){
    @include('send.php');
    die();
}
add_action('wp_ajax_pdfDownloadSend', 'pdfDownloadSend');
add_action('wp_ajax_nopriv_pdfDownloadSend', 'pdfDownloadSend');

AJAX:

            $container.find('#pdfdownload_form').submit(function(e) {
                var nl,
                    subscribering;

                e.preventDefault();

                nl = $container.find('#listvalue').val();

                if ($container.find('#subscribering').is(':checked')) {
                    subscribering = 'yes';
                }
                else {
                    subscribering = 'no';
                }

                $.ajax({
                    url: pdfdownload.ajax_url,
                    type: 'post',
                    data: {
                        emailer: $container.find('#pdfdownload_email').val(),
                        downloadurl: $container.find('#pdfdownload_downloadurl').val(),
                        subject: $container.find('#pdfdownload_subject').val(),
                        subscribering: 'yes',
                        nl: nl
                    },
                    beforeSend: function () {
                        $container.find('#pdfdownload_processing').show();
                    },
                    complete: function () {
                        $container.find('#pdfdownload_processing').hide();
                    },
                    success: function () {
                        $container.find('#pdfdownload_thankyou').show();

                        setTimeout(function () {
                            $container.find('#pdfdownload_thankyou').fadeOut(250);
                        }, 3001);
                    }
                });

                return false;
            });

邮件程序(send.php):

<?php 

require_once("../../../wp-load.php");

if ($_SERVER["REQUEST_METHOD"]=="POST"){
}
else 
    echo "Failed";  

// CONVERTED VARS
$downloadurl = $_POST['downloadurl'];    

//EMAIL CREDENTIALS
$emailer = sanitize_email( $_POST['emailer'] );

$subject = $_POST['subject'];
$headers = array('Content-Type: text/html; charset=UTF-8');
$body = "RANDOM BODY HERE with some variables like $downloadurl";

wp_mail( $emailer, $subject, $body, $headers );

提前谢谢!

0 个答案:

没有答案