在电子邮件主题 - PHP 邮件程序中输入值



我希望名称字段的值出现在我网站用户的邮件主题中。我正在使用 phpmailer 插件。 当前显示"来自用户的消息"。

处理程序.php:

$pp = new FormHandler(); 
$validator = $pp->getValidator();
$validator->fields(['name','email'])->areRequired()->maxLength(50);
$validator->field('email')->isEmail();
$validator->field('message')->maxLength(6000);
$validator->CharSet = 'UTF-8';

表单处理程序.php:

public function __construct()
{
$this->emails = array();
$this->validator = FormValidator::create();
$this->mailer = new PHPMailer;
$this->mail_template='';
$this->mailer->Subject = "Message from the user";
$host = isset($_SERVER['SERVER_NAME'])?$_SERVER['SERVER_NAME']:'localhost';
$from_email ='forms@'.$host;
$this->mailer->setFrom($from_email,'BanerBunny.pl',false);
$this->captcha = false;   
$this->attachments = [];
$this->recaptcha =null;
}

和 html:

<div id="form-main">
<div id="form-div">
<form class="montform" id="reused_form" enctype=&quot;multipart/form-data&quot;>
<p class="name">
<input name="name" type="text" class="feedback-input" placeholder="Imię i Nazwisko"
id="name" required/>
</p>
</form>
</div>
</div>

而不是

$this->mailer->Subject = "Message from the user";

尝试使用:

$this->mailer->Subject = ($_POST['name']);

它应该可以正常工作。

表单通过 JQuery/AJAX 提交代码 是的,我尝试使用此变量:$ this-> mailer-> Subject = $ 验证器->字段("名称"(。不幸的是,表格根本没有发送。

形式.js

$(function () {
function after_form_submitted(data) {
if (data.result == 'success') {
$('form#reused_form').hide();
$('#success_message').css('display', 'flex');
$('#error_message').hide();
}
else {
$('#error_message').append('<ul></ul>');
jQuery.each(data.errors, function (key, val) {
$('#error_message ul').append('<li>' + key + ':' + val + '</li>');
});
$('#success_message').hide();
$('#error_message').show();
//reverse the response on the button
$('button[type="button"]', $form).each(function () {
$btn = $(this);
label = $btn.prop('orig_label');
if (label) {
$btn.prop('type', 'submit');
$btn.text(label);
$btn.prop('orig_label', '');
}
});
}//else
}
$('#reused_form').submit(function (e) {
e.preventDefault();
$form = $(this);
//show some response on the button
$('button[type="submit"]', $form).each(function () {
$btn = $(this);
$btn.prop('type', 'button');
$btn.prop('orig_label', $btn.text());
$btn.text('Wysyłanie ...');
});

var formdata = new FormData(this);
$.ajax({
type: "POST",
url: 'handler.php',
data: formdata,
success: after_form_submitted,
dataType: 'json',
processData: false,
contentType: false,
cache: false
});
});

最新更新