I've set up my form and I'm unsure why the email is being sent and received, but does not include the 'message' field.
I have tried changing the ID's and testing different options but it doesn't seem to send the message
I had the issue a while back with another website but I was able to fix it and I don't remember how.
The reference used is $comment and I've used id=comment so I'm unsure why it's not sending it! Any help much appreciated. I've read other posts on here and no one has a similar issue from what I know.
Here is my website code:
<!-- Form -->` `
<form method="post" action="/contact.php" name="contactform" id="contactform" class="form form-stacked c-form">
<fieldset>
<input name="name" type="text" id="name" placeholder="Your Name" />
<input name="email" type="text" id="email" placeholder="Your E-mail" />
<textarea name="comment" id="comment" placeholder="Message"></textarea>
<input name="verify" type="text" id="verify" size="4" value="" placeholder="3 + 1 =" />
<input type="submit" class="submit btn outline" id="submit" value="Send message" />
</fieldset>
</form>
</div>
Here is my contact form .php
<?php
if(!$_POST) exit;
// Email address verification, do not edit.
function isEmail($email) {
return(preg_match("/^[-_.[:alnum:]]+#((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)$|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i",$email));
}
if (!defined("PHP_EOL")) define("PHP_EOL", "\r\n");
$name = $_POST['name'];
$email = $_POST['email'];
$comment = $_POST['comment'];
//$verify = $_POST['verify'];
if(trim($name) == '') {
echo '<div class="error_message">Attention! You must enter your name.</div>';
exit();
} else if(trim($email) == '') {
echo '<div class="error_message">Attention! Please enter a valid email address.</div>';
exit();
} else if(trim($comment) == '') {
echo '<div class="error_message">Attention! Please enter a message.</div>';
exit();
} else if(!isEmail($email)) {
echo '<div class="error_message">Attention! You have enter an invalid e-mail address, try again.</div>';
exit();
}
/*
if(trim($subject) == '') {
echo '<div class="error_message">Attention! Please enter a subject.</div>';
exit();
} else if(trim($comment) == '') {
echo '<div class="error_message">Attention! Please enter your message.</div>';
exit();
} else if(!isset($verify) || trim($verify) == '') {
echo '<div class="error_message">Attention! Please enter the verification number.</div>';
exit();
} else if(trim($verify) != '4') {
echo '<div class="error_message">Attention! The verification number you entered is incorrect.</div>';
exit();
}
*/
if(get_magic_quotes_gpc()) {
$comment = stripslashes($comment);
}
// Configuration option.
// Enter the email address that you want to emails to be sent to.
// Example $address = "joe.doe#yourdomain.com";
$address = "support#idomain.sx";
// Configuration option.
// i.e. The standard subject will appear as, "You've been contacted by John Doe."
// Example, $e_subject = '$name . ' has contacted you via Your Website.';
$e_subject = 'Email from: ' . $name . '.';
// Configuration option.
// You can change this if you feel that you need to.
// Developers, you may wish to add more fields to the form, in which case you must be sure to add them here.
$e_body = "You have been contacted by $name with regards to $subject, their additional message is as follows." . PHP_EOL . PHP_EOL;
$e_content = "\"$comment\"" . PHP_EOL . PHP_EOL;
$e_reply = "You can contact $name via email, $email or via phone $phone";
$msg = wordwrap( $e_body . $e_content . $e_reply, 70 );
$headers = "From: $email" . PHP_EOL;
$headers .= "Reply-To: $email" . PHP_EOL;
$headers .= "MIME-Version: 1.0" . PHP_EOL;
$headers .= "Content-type: text/plain; charset=utf-8" . PHP_EOL;
$headers .= "Content-Transfer-Encoding: quoted-printable" . PHP_EOL;
if(mail($address, $e_subject, $msg, $headers)) {
// Email has sent successfully, echo a success page.
echo "<fieldset>";
echo "<div id='success_page'>";
echo "<strong class=\"success\">Email Sent Successfully.</strong>";
echo "<p>Thank you <strong>$name</strong>, please allow up to 5 business days for a response.</p>";
echo "</div>";
echo "</fieldset>";
} else {
echo 'ERROR!';
}
Your textarea is named comments
<textarea name="comments" id="comments" placeholder="Message"></textarea>
But here it's looking for comment
$comment = $_POST['comment'];
Make sure the name is the same as the $_POST variable
Remember form data is appended to the name of the input, not the id
EDIT
$e_content = "\"$comment\"" . PHP_EOL . PHP_EOL;
You aren't concatenating your string and variable. Change it to:
$e_content = $comment . PHP_EOL . PHP_EOL;
I don't know what the backslashes are for. If they are required, change it to:
$e_content = "\" . $comment . "\" . PHP_EOL . PHP_EOL;
Change the $comment = $_POST['comment'];
into
$comment = $_POST['comments'];
Your textarea is named comments
<textarea name="comments" id="comments" placeholder="Message"></textarea>
But here it is looking for comment
$comment = $_POST['comment'];
Make sure the name is the same as the $_POST variable. Remember that form data is appended to the name of the input, not the id.
Edit:
$e_content = "\"$comment\"" . PHP_EOL . PHP_EOL;
You aren't concatenating your string and variable. Change it to:
$e_content = $comment . PHP_EOL . PHP_EOL;
I don't know what the backslashes are for. If they are required, change it to:
$e_content = "\" . $comment . "\" . PHP_EOL . PHP_EOL;
Related
The mail is sent successfully to my domain-mail. however, the 'phone' is not sent in the mail content.
The content of the mail comes like this.
You have been contacted by yourname with regards, their additional message
is as follows.
"What I want to say~~ "
You can contact yourname via email, omain#domain or via phone
What's the problem?
<form method="post" action="php/contact.php" name="contactform" id="contactform">
<input name="name" type="text" id="name" onClick="this.select()" value="Name" >
<input name="email" type="text" id="email" onClick="this.select()" value="E-mail" >
<input type="text" name="phone" id="phone" onClick="this.select()" value="Phone" />
<textarea name="comments" id="comments" onClick="this.select()" >Message</textarea>
<button type="submit" id="submit" data-top-bottom="transform: translateY(-50px);" data-bottom-top="transform: translateY(50px);"><span>Send Message </span></button>
</form>
<?php
require 'PHPMailer-master/PHPMailerAutoload.php';
/*
* CONFIGURE EVERYTHING HERE
*/
// an email address that will be in the From field of the email.
$fromEmail = $_REQUEST['email'] ;
$fromName = $_REQUEST['name'] ;
$to_Email = "my#domain.com";
// Email address verification, do not edit.
function isEmail($email) {
return filter_var($email, FILTER_VALIDATE_EMAIL);
}
if (!defined("PHP_EOL")) define("PHP_EOL", "\r\n");
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$comments = $_POST['comments'];
if(trim($name) == '') {
echo '<div class="error_message">You must enter your name.</div>';
exit();
} else if(trim($email) == '') {
echo '<div class="error_message"> Please enter a valid email address.</div>';
exit();
} else if(trim($phone) == '') {
echo '<div class="error_message">Please enter a valid phone number.</div>';
exit();
} else if(!is_numeric($phone)) {
echo '<div class="error_message">Phone number can only contain digits.</div>';
exit();
} else if(!isEmail($email)) {
echo '<div class="error_message">You have enter an invalid e-mail address, try again.</div>';
exit();
}
if(trim($comments) == '') {
echo '<div class="error_message">Please enter your message.</div>';
exit();
}
if(get_magic_quotes_gpc()) {
$comments = stripslashes($comments);
}
// Configuration option.
// Enter the email address that you want to emails to be sent to.
// Example $address = "joe.doe#yourdomain.com";
//$address = "my#domain.com";
$address = "my#domain.com";
// Configuration option.
// i.e. The standard subject will appear as, "You've been contacted by John Doe."
// Example, $e_subject = '$name . ' has contacted you via Your Website.';
$e_subject = 'You\'ve been contacted by ' . $name . '.';
// Configuration option.
// You can change this if you feel that you need to.
// Developers, you may wish to add more fields to the form, in which case you must be sure to add them here.
$e_body = "You have been contacted by $name with regards, their additional message is as follows." . PHP_EOL . PHP_EOL;
$e_content = "\"$comments\"" . PHP_EOL . PHP_EOL;
$e_reply = "You can contact $name via email, $email or via phone $phone";
$msg = wordwrap( $e_body . $e_content . $e_reply, 70 );
$headers = "From: $email" . PHP_EOL;
$headers .= "Reply-To: $email" . PHP_EOL;
$headers .= "MIME-Version: 1.0" . PHP_EOL;
$headers .= "Content-type: text/plain; charset=utf-8" . PHP_EOL;
$headers .= "Content-Transfer-Encoding: quoted-printable" . PHP_EOL;
if(mail($address, $e_subject, $msg, $headers)) {
// Email has sent successfully, echo a success page.
echo "<fieldset>";
echo "<div id='success_page'>";
echo "<h3>Email Sent Successfully.</h3>";
echo "<p>Thank you <strong>$name</strong>, your message has been submitted to us.</p>";
echo "</div>";
echo "</fieldset>";
} else {
echo 'ERROR!';
}
It seems to me that this needs to be corrected...
$e_reply =
<input type="text" name="phone" id="phone" onClick="this.select()" value="Phone" />
by removing "/" at the end of the tag may help you.
I have a problem that after I fill out the contact form on my HTML website I receive over 50 same E-mails. Its a HTML form connected to contact.php file which code is shown bellow. I have set everything but maybe there is a problem in my code or somewhere else.
My code is over here
<?php
if(!$_POST) exit;
// Email address verification, do not edit.
function isEmail($email) {
return(preg_match("/^[-_.[:alnum:]]+#((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+ (ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)$|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i",$email));
}
if (!defined("PHP_EOL")) define("PHP_EOL", "\r\n");
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$subject = $_POST['subject'];
$comments = $_POST['comments'];
$verify = $_POST['verify'];
if(trim($name) == '') {
echo '<div class="error_message">Vyplnte meno.</div>';
exit();
} else if(trim($email) == '') {
echo '<div class="error_message">Vyplnte email.</div>';
exit();
} else if(!isEmail($email)) {
echo '<div class="error_message">Zadali ste nesprávny e-mail, skúste to znovu.</div>';
exit();
}
if(trim($comments) == '') {
echo '<div class="error_message">Vyplnte text správy.</div>';
exit();
}
if(get_magic_quotes_gpc()) {
$comments = stripslashes($comments);
}
// Configuration option.
// Enter the email address that you want to emails to be sent to.
// Example $address = "joe.doe#yourdomain.com";
$address = "noreply#marcelaskolenia.sk";
$address = "lubosmasura#gmail.com";
$toCustomer = $email;
// Configuration option.
// i.e. The standard subject will appear as, "You've been contacted by John Doe."
// Example, $e_subject = '$name . ' has contacted you via Your Website.';
$e_subject = 'Mate novu spravu od ' . $name . '.';
// Configuration option.
// You can change this if you feel that you need to.
// Developers, you may wish to add more fields to the form, in which case you must be sure to add them here.
$e_body = "Mate novu spravu od $name." . PHP_EOL . PHP_EOL;
$e_content = "\"$subject\"" . "\"$comments\"" . PHP_EOL . PHP_EOL;
$e_reply = "Kontaktujte $name cez email, $email alebo cez mobil $phone";
$msg = wordwrap( $e_body . $e_content . $e_reply, 70 );
$headers .= 'To: Test <noreply#marcelaskolenia.sk>' . "\r\n";
$headers .= 'From: Testk <noreply#marcelaskolenia.sk>' . "\r\n";
$headers .= "MIME-Version: 1.0" . PHP_EOL;
$headers .= "Content-type: text/plain; charset=utf-8" . PHP_EOL;
$headers .= "Content-Transfer-Encoding: quoted-printable" . PHP_EOL;
if(mail($address, $e_subject, $msg, $headers)) {
// Email has sent successfully, echo a success page.
echo "<fieldset>";
echo "<div id='success_page'>";
echo "<h3 class'mark'>Sprava bola odoslana.</h3>";
echo "<p>Dakujeme <strong>$name</strong>, Vasa sprava nam bude dorucena.</p>";
echo "</div>";
echo "</fieldset>";
} else {
echo 'ERROR!';
}
HTML code
<div class="contact_form">
<div id="message"></div>
<form id="contactform" class="row" action="contact.php" name="contactform" method="post">
<div class="col-md-12">
<input type="text" name="name" id="name" class="form-control" placeholder="Meno">
<input type="text" name="email" id="email" class="form-control" placeholder="Email">
<input type="text" name="phone" id="phone" class="form-control" placeholder="Telefónne číslo">
<input type="text" name="subject" id="subject" class="form-control" placeholder="Predmet">
<textarea class="form-control" name="comments" id="comments" rows="6" placeholder="Text správy"></textarea>
<button type="submit" value="SEND" id="submit" class="btn btn-primary"> ODOSLAŤ</button>
</div>
</form>
</div>
</div><!-- end col -->
Any Ideas why is this happening?
Thank you.
I've scoured the entire internet trying to find a solution to what I'm missing here (or doing wrong). My form doesn't validate even when the check box is checked. Everything else works fine.
It's that checkbox I can't get to work right.
I've tried many different ideas, but it won't validate even with the "terms" checked (such as this example below).
Here's my HTML:
<div class="form-check">
<input type="checkbox" class="form-check-input" name="terms" id="terms" />
<label class="form-check-label" for="terms"><p>I agree to terms of service.</p></label>
</div>
Here's my entire PHP validation (updated with the comments/answers below):
<?php
if(!$_POST) exit;
// Email address verification.
function isEmail($email) { // lots of email validation stuff in here // }
if (!defined("PHP_EOL")) define("PHP_EOL", "\r\n");
$name = $_POST['name'];
$email = $_POST['email'];
$website = $_POST['website'];
$subject = $_POST['subject'];
$comments = $_POST['comments'];
$terms = $_POST['terms'];
//set an error counter to trigger the `exit`
$error_counter = 0;
if(trim($name) == '') {
echo '<div class="error_message">Attention! You must enter your name</div>';
$error_counter++;
}
if(trim($email) == '') {
echo '<div class="error_message">Attention! Please enter a valid email
address.</div>';
$error_counter++;
}
if(!isEmail($email)) {
echo '<div class="error_message">Attention! You have entered an invalid e-
mail address, try again.</div>';
$error_counter++;
}
if(trim($subject) == '') {
echo '<div class="error_message">Attention! Please enter a subject.</div>';
$error_counter++;
}
if(trim($comments) == '') {
echo '<div class="error_message">Attention! Please enter your message.
</div>';
$error_counter++;
}
if(empty($terms)) {
echo '<div class="error_message">Attention! Please agree to our terms of
service.</div>';
$error_counter++;
}
//if `$error_counter > 0 > 0` it will trigger the `exit()` to stop the script and display the errors.
if($error_counter > 0){
exit();
}
if(get_magic_quotes_gpc()) {
$comments = stripslashes($comments);
}
// Configuration option.
// Enter the email address that you want to emails to be sent to.
// Example $address = "joe.doe#yourdomain.com";
$address = "cousinjack#mydomain.com";
// Configuration option.
// i.e. The standard subject will appear as, "You've been contacted by John Doe."
// Example, $e_subject = '$name . ' has contacted you via Your Website.';
$e_subject = 'You have been contacted by ' . $name . '.';
// Configuration option.
// You can change this if you feel that you need to.
// Developers, you may wish to add more fields to the form, in which case you must be sure to add them here.
$e_body = "You have been contacted by $name with regards to $subject, their additional message is as follows." . PHP_EOL . PHP_EOL;
$e_content = "\"$comments\"" . PHP_EOL . PHP_EOL;
$e_reply = "You can contact $name via email, $email ";
$msg = wordwrap( $e_body . $e_content . $e_reply, 70 );
$headers = "From: $email" . PHP_EOL;
$headers .= "Reply-To: $email" . PHP_EOL;
$headers .= "MIME-Version: 1.0" . PHP_EOL;
$headers .= "Content-type: text/plain; charset=utf-8" . PHP_EOL;
$headers .= "Content-Transfer-Encoding: quoted-printable" . PHP_EOL;
if(mail($address, $e_subject, $msg, $headers)) {
// Email has sent successfully, echo a success page.
echo "<fieldset>";
echo "<div id='success_page'>";
echo "<h1>Email Sent Successfully.</h1>";
echo "<p>Thank you <strong>$name</strong>, your message has been submitted to us.</p>";
echo "</div>";
echo "</fieldset>";
} else {
echo 'ERROR!';
}
?>
You don't set any value attribute for your checkbox :
<input type="checkbox" class="form-check-input" name="terms" id="terms" value="yes" />
More informations : https://developer.mozilla.org/fr/docs/Web/HTML/Element/Input/checkbox
I can see your checkbox has no value so the PHP part is getting a garbage/empty value.
In short, just add a required attribute in your HTML side. No need of a check at the server end
<div class="form-check">
<input type="checkbox" class="form-check-input" name="terms" id="terms" required/>
<label class="form-check-label" for="terms"><p>I agree to terms of service.</p></label>
</div>
The problem with your current validation is that you're using if-else wrongly and that you're using exit on every statement which will terminate your script prematurely.
You can do this instead:
For Terms:
<input type="checkbox" class="form-check-input" name="terms" id="terms" value="1"/>
//set an error counter to trigger the `exit`
$error_counter = 0;
if(trim($name) == '') {
echo '<div class="error_message">Attention! You must enter your name</div>';
$error_counter++;
}
if(trim($email) == '') {
echo '<div class="error_message">Attention! Please enter a valid email
address.</div>';
$error_counter++;
}
if(!isEmail($email)) {
echo '<div class="error_message">Attention! You have entered an invalid e-
mail address, try again.</div>';
$error_counter++;
}
if(trim($subject) == '') {
echo '<div class="error_message">Attention! Please enter a subject.</div>';
$error_counter++;
}
if(trim($comments) == '') {
echo '<div class="error_message">Attention! Please enter your message.</div>';
$error_counter++;
}
if(empty($terms)) {
echo '<div class="error_message">Attention! Please agree to our terms of service.</div>';
$error_counter++;
}
//if `$error_counter > 0 > 0` it will trigger the `exit()` to stop the script and display the errors.
if($error_counter > 0){
exit();
}
There's a more beautiful approach to do this. Feel free to add suggestions for the OP.
I have my form setup and working perfect, however I need to add attachment functionality (only) to this. I've reviewed several threads and tried implementing but with no luck.
I'm trying to add id='file-7'
HTML code:
<fieldset class="clean">
<textarea name="comments" id="comments" placeholder="Message*"></textarea>
</fieldset>
<fieldset class="percent-one-full">
<div class="box">
<input type="file" name="file-7[]" id="file-7" class="inputfile inputfile-6" data-multiple-caption="{count} files selected" multiple />
<label for="file-7"><span></span> <strong><svg xmlns="http://www.w3.org/2000/svg" width="20" height="17" viewBox="0 0 20 17"><path d="M10 0l-5.2 4.9h3.3v5.1h3.8v-5.1h3.3l-5.2-4.9zm9.3 11.5l-3.2-2.1h-2l3.4 2.6h-3.5c-.1 0-.2.1-.2.1l-.8 2.3h-6l-.8-2.2c-.1-.1-.1-.2-.2-.2h-3.6l3.4-2.6h-2l-3.2 2.1c-.4.3-.7 1-.6 1.5l.6 3.1c.1.5.7.9 1.2.9h16.3c.6 0 1.1-.4 1.3-.9l.6-3.1c.1-.5-.2-1.2-.7-1.5z"/></svg> Upload file…</strong></label>
<input name="send" type="submit" class="button red" id="submit" onClick="MM_validateForm('name','','R','bandname','','R', 'email','','RisEmail','comments','','R');return document.MM_returnValue" value="SEND"/>
JS code:
jQuery(document).ready(function(){
$('#cform').submit(function(){
var action = $(this).attr('action');
$("#message").slideUp(750,function() {
$('#message').hide();
$('#submit')
.after('<img src="images/nivo-preloader.gif" class="contact-loader" />')
.attr('disabled','disabled');
$.post(action, {
name: $('#name').val(),
email: $('#email').val(),
bandname: $('#bandname').val(),
osflow: $('#osflow').val(),
hiddenDiv: $('#hiddenDiv').val(),
hiddenDivv: $('#hiddenDivv').val(),
hiddenDivvv: $('#hiddenDivvv').val(),
hiddenDivvvv: $('#hiddenDivvvv').val(),
hiddenDivvvvv: $('#hiddenDivvvvv').val(),
comments: $('#comments').val(),
verify: $('#verify').val()
},
function(data){
document.getElementById('message').innerHTML = data;
$('#message').slideDown('slow');
$('#cform img.contact-loader').fadeOut('slow',function(){$(this).remove()});
$('#submit').removeAttr('disabled');
if(data.match('success') != null) $('#cform').slideUp('slow');
}
);
});
return false;
});
});
PHP code:
<?php
if(!$_POST) exit;
// Email address verification, do not edit.
function isEmail($email) {
return(preg_match("/^[-_.[:alnum:]]+#((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)$|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i",$email));
}
if (!defined("PHP_EOL")) define("PHP_EOL", "\r\n");
print_r($_POST);
$name = $_POST['name'];
$email = $_POST['email'];
$_POST['bandname'];
$_POST['osflow'];
$_POST['hiddenDiv'];
$_POST['hiddenDivv'];
$_POST['hiddenDivvv'];
$_POST['hiddenDivvvv'];
$_POST['hiddenDivvvvv'];
$comments = $_POST['comments'];
//$verify = $_POST['verify'];
if(trim($name) == '') {
echo '<div class="error_message">Attention! You must enter your name.</div>';
exit();
} else if(trim($email) == '') {
echo '<div class="error_message">Attention! Please enter a valid email address.</div>';
exit();
} else if(!isEmail($email)) {
echo '<div class="error_message">Attention! You have enter an invalid e-mail address, try again.</div>';
exit();
}
if(trim($comments) == '') {
echo '<div class="error_message">Please enter your message.</div>';
exit();
//} else if(!isset($verify) || trim($verify) == '') {
// echo '<div class="error_message">Please enter the verification number. </div>';
// exit();
//} else if(trim($verify) != '4') {
// echo '<div class="error_message">The verification number you entered is incorrect.</div>';
// exit();
}
if(get_magic_quotes_gpc()) {
$comments = stripslashes($comments);
}
// Configuration option.
// Enter the email address that you want to emails to be sent to.
// Example $address = "joe.doe#yourdomain.com";
//$address = "example#example.net";
$address = "info#example.com";
// Configuration option.
// i.e. The standard subject will appear as, "You've been contacted by John Doe."
// Example, $e_subject = '$name . ' has contacted you via Your Website.';
$e_subject = 'Decal Inquiry from ' . $name . '';
// Configuration option.
// You can change this if you feel that you need to.
// Developers, you may wish to add more fields to the form, in which case you must be sure to add them here.
$e_body = "You have been contacted by $name. The additional message is as follows." . PHP_EOL . PHP_EOL;
$e_body = "Name: $name" . PHP_EOL . "\r\n";
$e_body2 = "Email: $email" . PHP_EOL . "\r\n";
$e_custom = "Band Name: $bandname" . PHP_EOL . "\r\n";
$e_custom2 = "Interest In: $osflow" . PHP_EOL . "\r\n";
$e_custom3 = "Drum Size: $hiddenDiv" . PHP_EOL . "\r\n";
$e_custom3 = "Drum Head Color: $hiddenDivv" . PHP_EOL . "\r\n";
$e_custom4 = "Mic Port Position: $hiddenDivvv" . PHP_EOL . "\r\n";
$e_custom5 = "Banner Color: $hiddenDivvvv" . PHP_EOL . "\r\n";
$e_custom6 = "Banner Size: $hiddenDivvvvv" . PHP_EOL . "\r\n";
$e_content .="Content-Disposition: attachment; filename=$file-7" . "\r\n";
$e_content = "Comments: $comments" . PHP_EOL . PHP_EOL;
$e_reply = "You can contact $name via email at $email.";
$msg = wordwrap( $e_body . $e_body2 . $e_custom . $e_custom2 . $e_custom3 . $e_custom4 . $e_custom5 . $e_custom6 . $e_custom7 . $e_content . $e_reply, 70 );
$headers = "From: $email" . PHP_EOL;
$headers .= "Reply-To: $email" . PHP_EOL;
$headers .= "MIME-Version: 1.0" . PHP_EOL;
$headers .= "Content-type: text/plain; charset=utf-8" . PHP_EOL;
$headers .= "Content-Transfer-Encoding: quoted-printable" . PHP_EOL;
if(mail($address, $e_subject, $msg, $headers)) {
// Email has sent successfully, echo a success page.
echo "<fieldset>";
echo "<div id='success_page'>";
echo "<h1>Email Sent Successfully.</h1>";
echo "<p>Thank you <strong>$name</strong>, we've received your inquiry and will be in touch shortly.</p>";
echo "</div>";
echo "</fieldset>";
} else {
echo 'ERROR!';
}
Any help would be much appreciated!
I would like to know why can't I receive the check-box value in my PHP email sender?
Here is the html:
<form method="post" action="send.php" name="cform" id="cform" class="form-signin" role="form">
<input name="name" id="name" type="text" class="form-control" placeholder="Your name and surname..." >
<input name="email" id="email" type="email" class="form-control" placeholder="Your email address..." >
<textarea name="comments" id="comments" class="form-control" placeholder="Your request..."></textarea>
<p>
<input type="checkbox" name="newsletter" id="newsletter" value="Yes" checked>
<span>I would like to receive the newsletter</span>
</p>
<input type="submit" id="submit" name="submit" class="lightButton" value="Submit >">
<div id="simple-msg"></div>
</form>
And here's the relevant part of the PHP code I found on the Internet ( don't know if here or in a blog, I'm kind of new to PHP so I can't do it from scratch ) and modified to my needs.
<?php
if(!$_POST) exit;
if (!defined("PHP_EOL")) define("PHP_EOL", "\r\n");
$name = $_POST['name'];
$email = $_POST['email'];
$comments = $_POST['comments'];
$x_newsletter = $_POST['newsletter'];
$address = "xxx#gmail.com";
$e_subject = 'Richiesta contatto da ' . $name . '.';
$e_body = "Richiesta contatto da parte di $name:" . PHP_EOL . PHP_EOL;
$e_content = "\"$comments\"" . PHP_EOL . PHP_EOL;
$e_checkNl = "Inviare newsletter: $x_newsletter" . PHP_EOL . PHP_EOL;
$e_reply = "$name\n$email";
$msg = wordwrap( $e_body . $e_content . $e_checkNl . $x_newsletter . $e_reply, 70 );
$headers = "From: $email" . PHP_EOL;
$headers .= "Reply-To: $email" . PHP_EOL;
$headers .= "MIME-Version: 1.0" . PHP_EOL;
$headers .= "Content-type: text/plain; charset=utf-8" . PHP_EOL;
$headers .= "Content-Transfer-Encoding: quoted-printable" . PHP_EOL;
?>
I put the $x_newsletter variable to catch the check-box "Yes" value (or at least something like 0 or 1), and later in the code a $e_checkNl that would write the value in the mail.
Fact is that it is a week that I'm searching in stack-overflow for and answer and troubleshooting this PHP trying to figure this thing out but every email I receive from the PHP sender lacks of this important information.
I don't really know, it could be a typo, or some sort of syntax that I can't manage as a newbie, but it's driving me crazy.
Can you please help me?
I'm here should you need any other kind of information.
Thank you,
Nico
EDIT:
here is the full PHP page. Every "if" i put I always get a "NO" option that is totally weird...
<?php
if(!$_POST) exit;
// Email address verification, do not edit.
function isEmail($email) {
return(preg_match("/^[-_.[:alnum:]]+#((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)$|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i",$email));
}
if (!defined("PHP_EOL")) define("PHP_EOL", "\r\n");
print_r($_POST);
$name = $_POST['name'];
$email = $_POST['email'];
$comments = $_POST['comments'];
$x_newsletter = $_POST['newsletter'];
if(trim($name) == '') {
echo '<div class="error_message">Your name is required</div>';
exit();
} else if(trim($email) == '') {
echo '<div class="error_message">Insert valid email address</div>';
exit();
} else if(!isEmail($email)) {
echo '<div class="error_message">Invalid email address. Please retry. </div>';
exit();
}
if(trim($comments) == '') {
echo '<div class="error_message">Insert your messagge.</div>';
exit();
}
if(get_magic_quotes_gpc()) {
$comments = stripslashes($comments);
}
$address = "xxx#gmail.com";
$e_subject = 'Richiesta contatto da ' . $name . '.';
$e_body = "Richiesta contatto da parte di $name:" . PHP_EOL . PHP_EOL;
$e_content = "\"$comments\"" . PHP_EOL . PHP_EOL;
//checkbox
$e_checkNl = "Inviare newsletter: $x_newsletter" . PHP_EOL . PHP_EOL;
$e_reply = "$name\n$email";
$msg = wordwrap( $e_body . $e_content . $e_checkNl . $x_newsletter . $e_reply, 70 );
$headers = "From: $email" . PHP_EOL;
$headers .= "Reply-To: $email" . PHP_EOL;
$headers .= "MIME-Version: 1.0" . PHP_EOL;
$headers .= "Content-type: text/plain; charset=utf-8" . PHP_EOL;
$headers .= "Content-Transfer-Encoding: quoted-printable" . PHP_EOL;
if(mail($address, $e_subject, $msg, $headers)) {
// Email has sent successfully, echo a success page.
echo "<fieldset>";
echo "<div id='success_page'>";
echo "<h3>Request sent successfully</h3>";
echo "<p>Dear <strong>$name</strong>, Your request has been received, we will contact you as soon as possible.</p><p>Grazie,<br/>Top Italy Travel.</p>";
echo "<p>$e_checkNl</p>";
echo "</div>";
echo "</fieldset>";
} else {
echo 'ERRORE!';
}
But the last part makes the form show a div on page for successful or error request, while the first part is a simple form check.
I doubt those cause this issue.
This will give you your desired result:
Replace $x_newsletter = $_POST['newsletter']; with:
$x_newsletter = (isset($_POST['newsletter'])) ? $_POST['newsletter'] : 'No';