0

Hello I have a very simple html/PHP email form, it worked fine until I added check boxes to my form and tried to get them to submit with all the other information. Now it is not sending an email to the address at all. Another change I made is that instead of my html action being action="mail.php" I changed it to link to a thank you page, so action="thankyou.html." Would that be messing anything up? I am not very good with PHP so if anyone could give advice it would be much appreciated, thank you in advance

HTML

<form action="mail.php" method="POST">
<p>Name</p> 
<input type="text" name="name">
<p>Email</p> 
<input type="text" name="email">
<p>Phone Type: Apple/Android/other</p> 
<input type="text" name="phone">
<p>Interested in BETA testing?<br><span style="font-size:9pt; font-weight: 300;">(Win prizes! Have fun! Be invited to excluseive Dapp parties! It's super easy and you can opt out at any time)</span></p> 
<div class="checkbox">

<input type="checkbox" name="check[]" value="YES" checked>
<label for="option1">Yes</label>
<input type="checkbox" name="check[]" value="NO">
<label for="option2">No</label>   
</div>        
<button type="submit" name="submit" value="submit" style="margin-top:15px">Dapp us up!</button>
</form>

PHP

<?php
if(isset($_POST['submit']))
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
foreach($_POST['check'] as $value) {
$check_msg .= "Checked: $value\n";
}
$body = "From: $email\n Phone: $phone\n BETA:\n $value\n $check_msg";
$to = "dappusup@gmail.com";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";

if ($_POST['submit']) {
if (mail ($to, $subject, $body, $mailheader)) { 
    echo 'Your message has been sent!';
}
}
header("Location: thankyou.html");
exit();
?>
  • Post the error. The problem could be in the `foreach` statement. – Cookie Ninja Jun 25 '16 at 03:31
  • Yes, actually there are more errors in your script , First of all change back to action="mail.php" and remove _target_, Then in the following line of code `$body = "From: $email\n Phone: $phone\n BETA:\n $check\n $check_msg";` You are using $check variable , and this is not exists in your script at all, remove that , and at last try using **isset** to check if a variable is set or not ? – Neeraj Jun 25 '16 at 03:49
  • Hi thank you for responding! I'm working pretty blind here (as you can probably tell) so I really appreciate it. I updated the code above to reflect what I have now, but it still does not work /: Zange-chan, I'm not sure how to post the error I'm sorry! – Anja Maria Jun 25 '16 at 16:33

0 Answers0