大家好我的ajax中的表单有问题,我使用ajaxSubmit因为我需要在表单中上传文件,所以这是我的表单的jquery代码:
var send_form = function(form_id, btn_id, fail_id, done_id){
var sending_contact_form = false;
var contact_captcha = $('.codecatch').text();
setTimeout(function(){
$(".botCode").each(function(){
$(this).val(contact_captcha);
});
}, 3000);
$(form_id).submit(function(e){
e.preventDefault();
e.stopPropagation();
var form = $(this).ajaxSubmit({});
if ($(".codecatch").html() == $(".botCode").val() ) {
if(!sending_contact_form){
sending_contact_form = true;
var action = $(this).attr('action');
var btn = $(this).find(btn_id);
btn.val($(btn_id).data('sending'));
var xhr = form.data('jqxhr');
xhr.fail(function(){
$(done_id).fadeOut();
$(fail_id).fadeIn();
}).done(function(data){
btn.val($(btn_id).data('send'));
$(fail_id).fadeOut();
$(done_id).fadeIn().css("display","inline-block");
//$(this).trigger("reset");
setTimeout(function() {
$(done_id).fadeOut();
}, 3000 );
sending_contact_form = false;
},'json');
}
}else{
$(done_id).fadeOut();
$(fail_id).fadeIn().css("display","inline-block");
setTimeout(function() {
$(fail_id).fadeOut();
}, 3000 );
}
return false;
});
}
这是我的表单流程代码
if(count($_POST)>0 && $_POST['f_codecatch'] == $contact_captcha_code){
$attachments = [];
if(!empty($_FILES)){
$files = $_FILES; // file array
foreach ($files as $file) {
$upload_dir = wp_upload_dir();
$path = $upload_dir['basedir'].'/files/'; //upload dir.
if(!is_dir($path)) { mkdir($path); }
$attachment_id = upload_user_file( $file ,$path);
$attachments[] = $path . $file['name'];
}
}
$msg = '';
$msg .= '<html><body>';
$msg .= '<div style="padding-top: 30px;padding-right: 20%;padding-left: 20%;">';
$msg .= '<div style="width: 100%; margin: 0 auto; text-align: center; margin-bottom: 20px;">';
$msg .= '<img src="'.THEME_PATH.'/images/logo-atiker.png" width="250px" alt="Atiker México" title="Atiker México">';
$msg .= '</div>';
if (!empty($_POST['f_name'])) {
$msg .= '<div style="display: -webkit-box;display: -webkit-flex;display: -ms-flexbox;display: flex;width: 100%;padding: 10px;-webkit-justify-content: space-around;-ms-flex-pack: distribute;justify-content: space-around;-webkit-box-align: center;-webkit-align-items: center;-ms-flex-align: center;align-items: center;border-top: 1px dashed #c3c3c3;">';
$msg .= '<div style="-webkit-box-flex: 1;-webkit-flex: 1;-ms-flex: 1;flex: 1;font-weight: 700;">';
$msg .= 'Nombre:';
$msg .= '</div>';
$msg .= '<div style="-webkit-box-flex: 1;-webkit-flex: 1;-ms-flex: 1;flex: 1;color: #6b6b6b;font-weight: 700;">';
$msg .= htmlspecialchars($_POST['f_name']);
$msg .= '</div>';
$msg .= '</div>';
}
if (!empty($_POST['f_email'])) {
$msg .= '<div style="display: -webkit-box;display: -webkit-flex;display: -ms-flexbox;display: flex;width: 100%;padding: 10px;-webkit-justify-content: space-around;-ms-flex-pack: distribute;justify-content: space-around;-webkit-box-align: center;-webkit-align-items: center;-ms-flex-align: center;align-items: center;border-top: 1px dashed #c3c3c3;">';
$msg .= '<div style="-webkit-box-flex: 1;-webkit-flex: 1;-ms-flex: 1;flex: 1;font-weight: 700;">';
$msg .='Email:';
$msg .= '</div>';
$msg .= '<div style="-webkit-box-flex: 1;-webkit-flex: 1;-ms-flex: 1;flex: 1;color: #6b6b6b;font-weight: 700;">';
$msg .= htmlspecialchars($_POST['f_email']);
$msg .= '</div>';
$msg .= '</div>';
}
if (!empty($_POST['f_phone'])) {
$msg .= '<div style="display: -webkit-box;display: -webkit-flex;display: -ms-flexbox;display: flex;width: 100%;padding: 10px;-webkit-justify-content: space-around;-ms-flex-pack: distribute;justify-content: space-around;-webkit-box-align: center;-webkit-align-items: center;-ms-flex-align: center;align-items: center;border-top: 1px dashed #c3c3c3;">';
$msg .= '<div style="-webkit-box-flex: 1;-webkit-flex: 1;-ms-flex: 1;flex: 1;font-weight: 700;">';
$msg .= 'Teléfono:';
$msg .= '</div>';
$msg .= '<div style="-webkit-box-flex: 1;-webkit-flex: 1;-ms-flex: 1;flex: 1;color: #6b6b6b;font-weight: 700;">';
$msg .= htmlspecialchars($_POST['f_phone']);
$msg .= '</div>';
$msg .= '</div>';
}
if (!empty($_POST['f_type'])) {
$msg .= '<div style="display: -webkit-box;display: -webkit-flex;display: -ms-flexbox;display: flex;width: 100%;padding: 10px;-webkit-justify-content: space-around;-ms-flex-pack: distribute;justify-content: space-around;-webkit-box-align: center;-webkit-align-items: center;-ms-flex-align: center;align-items: center;border-top: 1px dashed #c3c3c3;">';
$msg .= '<div style="-webkit-box-flex: 1;-webkit-flex: 1;-ms-flex: 1;flex: 1;font-weight: 700;">';
$msg .= 'Tipo de Cotización:';
$msg .= '</div>';
$msg .= '<div style="-webkit-box-flex: 1;-webkit-flex: 1;-ms-flex: 1;flex: 1;color: #6b6b6b;font-weight: 700;">';
$msg .= htmlspecialchars($_POST['f_type']);
$msg .= '</div>';
$msg .= '</div>';
}
if (!empty($_POST['f_model'])) {
$msg .= '<div style="display: -webkit-box;display: -webkit-flex;display: -ms-flexbox;display: flex;width: 100%;padding: 10px;-webkit-justify-content: space-around;-ms-flex-pack: distribute;justify-content: space-around;-webkit-box-align: center;-webkit-align-items: center;-ms-flex-align: center;align-items: center;border-top: 1px dashed #c3c3c3;">';
$msg .= '<div style="-webkit-box-flex: 1;-webkit-flex: 1;-ms-flex: 1;flex: 1;font-weight: 700;">';
$msg .='Año y Modelo:';
$msg .= '</div>';
$msg .= '<div style="-webkit-box-flex: 1;-webkit-flex: 1;-ms-flex: 1;flex: 1;color: #6b6b6b;font-weight: 700;">';
$msg .= htmlspecialchars($_POST['f_model']);
$msg .= '</div>';
$msg .= '</div>';
}
$msg .= '</div>';
$msg .= '</body></html>';
$to = 'myemail';//htmlspecialchars($_POST['f_email']);
$subject = htmlspecialchars($_POST['f_name']).' <'.htmlspecialchars($_POST['f_email']).'>';
$body = $msg;
$headers = array(
'From:'.htmlspecialchars($_POST['f_name']).' <'.htmlspecialchars($_POST['f_email']).'>',
'Content-Type: multipart/form-data; charset=UTF-8',
'Reply-To:'.htmlspecialchars($_POST['f_name']).' <'.htmlspecialchars($_POST['f_email']).'>'
);
wp_mail( $to, $subject, $body, $headers, $attachments);
echo json_encode(array('success'=>true));
exit;
}
我已经收到电子邮件了,但格式为html格式,是标题内容或建议是什么,因为我已经尝试了很多东西xD,感谢您的帮助
这是我收到的电子邮件
答案 0 :(得分:0)
答案 1 :(得分:0)
问题是标题这是重音的正确方法以及更多,感谢任何帮助:D
Content-type: text/html; charset=UTF-8