0

I've tried everything outlined in this tutorial.
But no matter what, when the checkbox script still produces an error message.

<?php
ini_set( display_errors, 1 );
error_reporting( E_ALL );
$email = $_POST['myEmail'];
$name = $_POST['myName'];
if (isset($_POST['news'])) {
    $checkBoxValue = "yes";
} else {
    $checkBoxValue = "no";
}
$to = "web@myemail.com";
$subject = "Add me to the Launch Day Notification List!";
$headers = "From:".$email;
$txt = "This person wishes to be added to the launch day notification list: $name\nDoes 
this person wish to subscribe to the newsletter? $news";
mail($to,$subject,$headers,$txt);
echo "Thank you for your inquiry, you will be added to our launch day notification 
list!";
?> 

client-side code:

<form  action="mail.php" method="post">
    Name: <input type="text" name="myName" class="contactform" placeholder="name"required><br>
    Email: <input type="text" name="myEmail" class="contactform" placeholder="you@youremail.com" required>
    <p>Would you like to subscribe to our newsletter?</p>
    <be>
    <input type="checkbox" name="news" value="Yes" checked>
    <label for="news">Yes, I would like to subscribe</label><br>
    <input class="btns" name="btn-send" id="mySubmit" type="submit" value="submit"> 
    <input class="btns" name="btn-reset" id="myReset" type="reset" value="reset">

</form>
סטנלי גרונן
  • 2,917
  • 23
  • 46
  • 68
  • Can you post your client-side code too? There isn't enough information to definitively say what the problem is here. – Ynhockey May 19 '20 at 14:22
  • If you get an `error message` then you shoudl be showing US the error mesage – RiggsFolly May 19 '20 at 14:24
  • @Ynhockey posted – ainteractive May 19 '20 at 14:24
  • Good code indentation would help us read the code and more importantly it will help **you debug your code** [Take a quick look at a coding standard](https://www.php-fig.org/psr/psr-12/) for your own benefit. You may be asked to amend this code in a few weeks/months and you will thank me in the end. – RiggsFolly May 19 '20 at 14:24

1 Answers1

0

You are not using the variable $checkBoxValue that you created, in the output line, so use $checkBoxValue instead of $news which does not actually exist. This will probably remove the error that you mention as well.

$txt = "This person wishes to be added to the launch day notification list: $name\n
Does this person wish to subscribe to the newsletter? $checkBoxValue ";
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149