Reputation: 11
Good Day,
I have a form that saves Name, Email, Subject, Tel Number, Message, and a checkbox.
I m sadly not so good in php at all. Im just started to learn the basics. Thats why i need a little help from you :)
The Form
<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>
Now i need this information: Name, Subject, Email, Number and if the checkbox was checked. I would like to include the Number and the checkbox info in the message, that will send as a email to me, because the Name, Subject and Email info will go in the email header.
I figured out how i could save all to the header, but im not really sure about how to include something in the message. Do i have to sent a HTML email for that? or can i do it without html?
There goes my php code
<?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( "[email protected]", $_POST['subject'], $_POST['message'], $headers );
}
?>
Thank you all for your help.
Upvotes: 0
Views: 64
Reputation: 121
Your question is not clear but assuming you want to append more text to the message?
You can do something like this:
$more_message = $_POST['name']. "hello, this is more \n";
mail( "[email protected]", $_POST['subject'], $more_message.$_POST['message'], $headers );
Update based on comment below on additional requirements:
$header_1 = $_POST['subject'] ."\n" .$_POST['name'] ."\n";
$more_message = $_POST['message']. "\n". $_POST['number'] ."\n". $_POST['Checkdata'];
something like this...
Upvotes: 1