美好的一天,
我有一个表格,可以保存姓名,电子邮件,主题,电话号码,留言和复选框。
令人遗憾的是,我根本不太喜欢php。我刚刚开始学习基础知识。这就是为什么我需要你的帮助:))
表格
<form class="contact-form" id="contact" role="form">
<!-- IF MAIL SENT SUCCESSFULLY -->
<h6 class="success">
<span class="olored-text icon_check"></span> Your Message has been send. </h6>
<!-- IF MAIL SENDING UNSUCCESSFULL -->
<h6 class="error">
<span class="colored-text icon_error-circle_alt"></span> Error </h6>
<div class="field-wrapper col-md-6">
<input class="form-control input-box" id="cf-name" type="text" name="cf-name" placeholder="Name*" required>
</div>
<div class="field-wrapper col-md-6">
<input class="form-control input-box" id="cf-email" type="email" name="cf-email" placeholder="E-Mail*" required>
</div>
<div class="field-wrapper col-md-6">
<input class="form-control input-box" id="cf-subject" type="text" name="cf-subject" placeholder="Subject*" required>
</div>
<div class="field-wrapper col-md-6">
<input class="form-control input-box" id="cf-number" type="tel" name="cf-number" placeholder="Number">
</div>
<div class="field-wrapper col-md-12">
<textarea class="form-control textarea-box" id="cf-message" rows="7" name="cf-message" placeholder="Message*" required></textarea>
</div>
<div class="form-check col-md-12">
<input type="checkbox" class="form-check-input" id="Checkdata" required>
<label class="form-check-label" for="Checkdata"> yes to this*</label>
</div>
<div class="col-md-12 ">
<p>*required</p>
</div>
<button class="btn standard-button" type="submit" id="cf-submit" name="submit" data-style="expand-left">Send</button>
</form>
现在我需要这些信息:名称,主题,电子邮件,号码以及是否选中了复选框。我想在邮件中包含号码和复选框信息,这些信息将作为电子邮件发送给我,因为姓名,主题和电子邮件信息将放在电子邮件标题中。
我想出了如何将所有内容保存到标题中,但我不确定如何在邮件中包含所有内容。我是否必须发送HTML电子邮件?或者我可以在没有HTML的情况下完成吗?
有我的PHP代码
<?php
if ( isset($_POST['email']) && isset($_POST['name']) && isset($_POST['subject']) && isset($_POST['number']) && isset($_POST['message']) && filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) ) {
$test = "/(content-type|bcc:|cc:|to:)/i";
foreach ( $_POST as $key => $val ) {
if ( preg_match( $test, $val ) ) {
exit;
}
}
$headers = 'From: ' . $_POST["name"] . '<' . $_POST["email"] . '>' . "\r\n" .
'Reply-To: ' . $_POST["email"] . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail( "hey@example.net", $_POST['subject'], $_POST['message'], $headers );
}
?>
谢谢大家的帮助。
答案 0 :(得分:1)
您的问题不明确,但假设您要在邮件中附加更多文字?
您可以这样做:
$more_message = $_POST['name']. "hello, this is more \n";
mail( "hey@example.net", $_POST['subject'], $more_message.$_POST['message'], $headers );
根据以下关于其他要求的评论进行更新:
$header_1 = $_POST['subject'] ."\n" .$_POST['name'] ."\n";
$more_message = $_POST['message']. "\n". $_POST['number'] ."\n". $_POST['Checkdata'];
像这样......