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 = "[email protected]";
$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="[email protected]" 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>
4
  • Can you post your client-side code too? There isn't enough information to definitively say what the problem is here. Commented May 19, 2020 at 14:22
  • If you get an error message then you shoudl be showing US the error mesage Commented May 19, 2020 at 14:24
  • @Ynhockey posted Commented May 19, 2020 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 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. Commented May 19, 2020 at 14:24

1 Answer 1

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 ";
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.