lundi 19 janvier 2015

Why does this php single checkbox value not showing in my email sender?

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 = "newsletter.nico@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





Aucun commentaire:

Enregistrer un commentaire