使用jQueryAjax跨站点提交表单,然后通过电子邮件发送

使用jQueryAjax跨站点提交表单,然后通过电子邮件发送,jquery,ajax,wordpress,forms,cross-domain,Jquery,Ajax,Wordpress,Forms,Cross Domain,我有注册表格,需要发送给第三方软件,然后我需要在成功提交后通过电子邮件发送表格内容 我使用jQueryAjax表单插件提交表单,然后在成功时调用jQueryAjax。我必须使用插件,因为我需要在表单中发送附件,而jquery serialize函数不包含文件。表单跨站点提交成功,但电子邮件脚本未运行 代码如下: 请发布脚本以便发送email@krishna添加了电子邮件脚本 var options = { success: showResponse, // post-s

我有注册表格,需要发送给第三方软件,然后我需要在成功提交后通过电子邮件发送表格内容

我使用jQueryAjax表单插件提交表单,然后在成功时调用jQueryAjax。我必须使用插件,因为我需要在表单中发送附件,而jquery serialize函数不包含文件。表单跨站点提交成功,但电子邮件脚本未运行

代码如下:


请发布脚本以便发送email@krishna添加了电子邮件脚本
var options = {
            success: showResponse,  // post-submit callback 
            // other available options: 
            url: 'url to third party software',         // override for form's 'action' attribute 
            type: 'post'        // 'get' or 'post', override for form's 'method' attribute 
        };
        // bind to the form's submit event 
        $('#main-form').ajaxSubmit(options);

        // post-submit callback 

        function showResponse() {
            var newCustomerForm = jQuery("#main-form").serialize();
            jQuery.ajax({
                type: "POST",
                url: "url to email script on local server",
                action: addCustomer,
                data: newCustomerForm,
                success: function (data) {
                    $('#form-container').html('<h3>Thank you. Your Online Application has been successfully submitted. </h3>');
                }
            });
        }




//php email sending script
    function addCustomer()
    {

        foreach ($_POST as $key => $value) 
        {

                    $str .= "<b> ".str_replace('_',' ',$key).":</b> $value<br>";
         }

        if(isset($_FILES['file1']))
        {
            move_uploaded_file($_FILES["file1"]["tmp_name"],WP_CONTENT_DIR .'/uploads/'.basename($_FILES['file1']['name']));
            $attachments[$s] = WP_CONTENT_DIR ."/uploads/".$_FILES["file1"]["name"];
        }

                                }


    ////////////////email settings///////////////////////////////////////////   
        $emailTo = 'email address';


                                add_filter('wp_mail_content_type',create_function('', 'return "text/html";'));
    wp_mail($emailTo, $subject, $body, $headers, $attachments);
    $emailSent = true;
                        ////////////////////////////////////////////////////////////////////////
    }
    add_action('wp_ajax_addCustomer', 'addCustomer');
    add_action('wp_ajax_nopriv_addCustomer', 'addCustomer');