PHP电子邮件表单在单词之间没有空格而没有特殊字符
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了PHP电子邮件表单在单词之间没有空格而没有特殊字符,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含4453字,纯文字阅读大概需要7分钟。
内容图文
![PHP电子邮件表单在单词之间没有空格而没有特殊字符](/upload/InfoBanner/zyjiaocheng/780/34abf258034c478bb4ec1a4bef6de255.jpg)
我已经构建了一个通过AJAX使用php邮件功能发送的表单.我的问题是当我的电子邮件通过时,所有空格都被”替换,而特殊字符被’@’等替换.
这是我的AJAX脚本:
<script>
jQuery(document).ready(function($) {
$('.builderForm').each(function() {
$(this).on("submit", function(event) {
event.preventDefault();
var formData = $(this).serialize();
var loading = '<div id="overlay"><img id="loading" src="<?php echo LAYERS_FORM_BUILDER__PLUGIN_URL;?>assets/images/loading.gif"></div>';
$(loading).appendTo('body');
$.ajax({
type : 'POST', // define the type of HTTP verb we want to use (POST for our form)
url : '<?php echo LAYERS_FORM_BUILDER__PLUGIN_URL;?>includes/class-send-form.php', // the url where we want to POST
data : {'formData' :formData}, // our data object
dataType : 'json', // what type of data do we expect back from the server
encode : true
})
.done(function(data) {
// log data to the console so we can see
//console.log(data);
setTimeout(function(){$('#overlay').hide();}, 4000);
$('#overlay').remove();
$('.successMsg').html("Message Was Sent Successfully!!");
setTimeout(function(){$('.successMsg').hide();}, 5000);
// Reset form after submission
$(".builderForm")[0].reset();
});
event.preventDefault();
});
});
});
</script>
我的PHP邮件处理程序代码:
$layers_email_address = '';
$layers_email_subject = '';
// if there are any errors in our errors array, return a success boolean of false
if (!empty($errors)) {
// if there are items in our errors array, return those errors
$data['success'] = false;
$data['errors'] = $errors;
} else {
parse_str($_REQUEST['formData'], $formFields)
//$formFields = explode('&', $_REQUEST['formData']);
$html='<html><body>';
foreach($formFields as $key => $value) {
$fields = explode('=', $key);
$field = $fields[0];
$value = $fields[1];
$html .= '<p><label>' . $key . ' :</label> ' . $value . '</p>';
}
$html .='</body></html>';
$to = "sam.skirrow@gmail.com";
$subject = "Form Submission";
$txt = $html;
$headers = "From: <sam.skirrow@gmail.com>". "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1"."\r\n";
mail($to,$subject,$txt,$headers);
// if there are no errors process our form, then return a message
// show a message of success and provide a true success variable
$data['success'] = true;
$data['message'] = 'Success!';
}
// return all our data to an AJAX call
echo json_encode($data);
我怎样才能使我的电子邮件成为痛苦文本,而不是忽略特殊字符?
出现多个复选框数据发送的问题,这里是动态创建复选框的代码(它位于foreach语句中,并在窗口小部件中的“select-options”文本区域的每一行填充每个复选框
if ($item['input_type'] == 'checkbox') { ?>
<div class="options_container">
<?php foreach(explode("\n", $item['select_options']) as $select_option) { ?>
<input type="checkbox" name="<?php echo $item['input_name']; ?>" value="<?php echo preg_replace('/\s+/','', $select_option); ?>" <?php if( $this->check_and_return( $item, 'required') ) { echo 'required'; } ?>><span class="checkbox_option"><?php echo $select_option; ?></span>
<?php } ?>
</div>
<?php }
编辑:php邮件处理程序的新代码:
$layers_email_address = '';
$layers_email_subject = '';
// if there are any errors in our errors array, return a success boolean of false
if (!empty($errors)) {
// if there are items in our errors array, return those errors
$data['success'] = false;
$data['errors'] = $errors;
} else {
parse_str($_REQUEST['formData'], $formFields)
$html = '<html><body>';
foreach ($formFields as $key => $value) {
$html .= '<p><label>' . $key . ' :</label> ' . $value . '</p>';
}
$html .= '</body></html>';
$to = 'sam.skirrow@gmail.com';
$subject = "Form Submission";
$txt = $html;
$headers = "From: <sam.skirrow@gmail.com>" . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1" . "\r\n";
mail($to, $subject, $txt, $headers);
// if there are no errors process our form, then return a message
// show a message of success and provide a true success variable
$data['success'] = true;
$data['message'] = 'Success!';
}
// return all our data to an AJAX call
echo json_encode($data);
解决方法:
功能parse_str()正是您所需要的.
使用parse_str($_ REQUEST [‘formData’],$formFields)]而不是$formFields = explode(‘&’,$_REQUEST [‘formData’]);
这将解析你的字符串$_REQUEST [‘formData’]以创建一个key =>的数组.变量$formFields中的值.
功能here的文档.
编辑:
对于foreach工作,您需要这样做:
foreach ($formFields as $key => $value) {
$html .= '<p><label>' . $key . ' :</label> ' . $value . '</p>';
}
内容总结
以上是互联网集市为您收集整理的PHP电子邮件表单在单词之间没有空格而没有特殊字符全部内容,希望文章能够帮你解决PHP电子邮件表单在单词之间没有空格而没有特殊字符所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。