所以这必须看作另一个PHP电子邮件问题。但是,在研究并尝试Stackoverflow上的所有可用回复之后,我似乎无法获得<textarea name="description"></textarea>
获取内容并将其与剩余的电子邮件$ to,$ from,$ body和$ headers一起发送:
这是HTML:
<form method="post" id="tarqus_form">
<div class="inner-frame inverse p-7">
<h5>Hola,</h5>
<div>
<h5>mi nombre es</h5>
<input type="text" class="name" name="name" placeholder="Nombre (obligatorio)" id="name">
</div>
<div>
<h5>y me gustaría saber</h5>
</div>
<div>
<h5>sobre:</h5>
<input type="text" class="subject" name="subject" placeholder="Asunto" id="asunto">
</div>
<div>
<h5>Me pueden responder</h5>
</div>
<div>
<h5>a este:</h5>
<input type="text" class="email" name="email" placeholder="Correo electrónico (obligatorio)" id="email">
</div>
<div>
<h5>Quisiera decir:</h5>
</div>
<div>
<!-- HERE's the textarea -->
<textarea name="description" rows="3" class="message" placeholder="Ingresa tu mensaje (obligatorio)" id="message"></textarea>
</div>
<div class="row pt-21">
<div class="col-md-6 p-0">
<h5>Antispam:</h5>
<div>
<h5>¿12-7+2?</h5>
</div>
<div>
<input type="text" class="antispam pl-0 mt-7 ml-0" name="antispam" placeholder="Respuesta (obligatorio)" id="antispam">
</div>
</div>
<div class="col-md-6 text-center">
<input type="submit" value="Enviar" class="submit uppercase">
</div>
</div>
</div>
</form>
我正在使用jQuery创建一些验证,如果它们通过,则调用POST方法。这不是问题,因为除了textarea上的消息之外,电子邮件实际上正在发送我需要的所有内容。 jQuery验证:
$("#tarqus_form").submit(function(e){
e.preventDefault();
var name = $("#name").val();
var subject = $("#asunto").val();
var email = $("#email").val();
var text = $("#message").val();
var antispam = $("#antispam").val();
var dataString = 'email=' + email + '&text=' + text + '&subject=' + subject + '&name=' + name;
// Custom RegExp for verifying email authenticity
function isValidEmail(emailAddress) {
var pattern = new RegExp(/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0- \uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i);
return pattern.test(emailAddress);
};
if (isValidEmail(email) && (name.length > 1) && (text.length > 1) && (antispam == 7)){
$.ajax({
type: "POST",
url: "/form.php",
data: dataString,
success: function(response){
console.log(response);
$('#tarqus_form').fadeOut(500);
$('.success').removeClass('hidden').fadeIn(500);
}
});
} else{
$('.error').removeClass('hidden').fadeIn(1000);
setTimeout(function(){
$('.error').addClass('hidden');
}, 5000);
}
return false;
});
当它通过时,表单根据此PHP代码发送电子邮件:
<?php
$name = $_POST['name'];
$subject = $_POST['subject'];
$email = $_POST['email'];
$message = $_POST['description'];
$from = 'TARQUS | Arquitectura MX <contacto@tarqus.mx>';
$headers.="From:".$from."\n";
$to = 'contacto@tarqus.mx';
$body = "Nombre: $name\n Asunto: $subject\n E-Mail: $email\n Mensaje: $message\n";
// detect & prevent header injections
$test = "/(content-type|bcc:|cc:|to:)/i";
foreach ( $_POST as $key => $val ) {
if ( preg_match( $test, $val ) ) {
exit;
}
}
@mail($to, $subject, $body, $headers);
?>
正如您所看到的,我正在为$_POST
textarea使用name="description"
方法。我也试过$_REQUEST
方法。
这是一个示例电子邮件,我对PHP代码所做的所有更改都发送了电子邮件,但$ body中的$ message除外:
Nombre: Name Lastname
Asunto: Subject
E-Mail: example@mail.com
Mensaje: === empty === :(
答案 0 :(得分:1)
你的php文件出错了
当您在ajax中发布DATA时,您发送TEXT而不是描述
$name = $_POST['name'];
$subject = $_POST['subject'];
$email = $_POST['email'];
$message = $_POST['text'];
$from = 'TARQUS | Arquitectura MX <contacto@tarqus.mx>';
$headers.="From:".$from."\n";