lundi 24 août 2015

PHP Form Mail with Checkbox Array not working

I have a PHP script that handles the $_POST output from my HTML form and sends it via php mail. I've used this script on stock-standard contact forms many times without a problem so I know it works. In this adaptation though, I'm also collection multiple checkbox values as an array and that's where I'm stuck. I've looked everywhere and tried pretty much every suggestion on here but with no joy. Here's my PHP & HTML. What am I missing?

Any help would be greatly appreciated.

<?php

// Define some constants

define( "RECIPIENT_NAME", "Name" ); //UPDATE THIS TO YOUR NAME
define( "RECIPIENT_EMAIL", "" ); //UPDATE THIS TO YOUR EMAIL ID
define( "EMAIL_SUBJECT", "" ); //UPDATE THIS TO YOUR SUBJECT

// Read the form values
$success = false;
$senderName = isset( $_POST['name'] ) ? preg_replace( "/[^\.\-\' a-zA-Z0-9]/", "", $_POST['name'] ) : "";
$senderSubject = isset( $_POST['subject'] ) ? preg_replace( "/[^\.\-\' a-zA-Z0-9]/", "", $_POST['subject'] ) : "";
$senderMail = isset( $_POST['mail'] ) ? preg_replace( "/[^\.\-\_\@a-zA-Z0-9]/", "", $_POST['mail'] ) : "";

// Sanitise inputs
$prints = str_replace(array("\n", "\r"), ' ', $prints);
$prints = implode(',',$_POST['prints']);

// Bot Trap
$email = isset($_POST['email'] ) ? preg_replace( "/[^\.\-\_\@a-zA-Z0-9]/", "", $_POST['email']) : "";
// $email is a hidden input so needs to be empty

$message = 'Name: '.$senderName.'<br/>Subject: '.senderSubject.'<br/>Email: '.$senderMail.'<br/>Prints: '.$prints;
// If all values exist, send the email
if ( $senderName && $senderSubject && $senderMail && $message && ($email ==  "") ) {
  $recipient = RECIPIENT_NAME . " <" . RECIPIENT_EMAIL . ">";
  $headers = "From: " . $senderName . " <" . $senderMail . ">\n";
  $headers .= "MIME-Version: 1.0\n"; 
  $headers .= "Content-Type: text/HTML; charset=ISO-8859-1\n";
 $success = mail( $recipient, EMAIL_SUBJECT, $message, $headers );

}

if ( $success ) {

header( 'Location: ../../thanks.html' );
}

else {

header( 'Location: ../../tryagain.html' );
}


<form name="order-form" id="order-form" action="sendselection.php" enctype="multipart/form-data" method="post">

<div class="reflow__item portrait">
<button type="button" class="lightbox_trigger" href="images/Image-001.jpg"><span class="glyphicon glyphicon-resize-full expand" title="Expand"></span></button>
<img src="images/Image-001.jpg" title="Image-001.jpg" alt="Image-001.jpg">
<div class="selection">
<label class="checkbox-inline 5x7" for="Image-001.jpg-5x7"><input class="5x7" type="checkbox" name="5x7[]" id="Image-001.jpg-5x7" value="Image-001.jpg" />5&times;7&middot;5 Prints</label>
<label class="checkbox-inline 8x12" for="Image-001.jpg-8x12"><input class="8x12" type="checkbox" name="8x12[]" id="Image-001.jpg-8x12" value="Image-001.jpg" />8&times;12 Prints</label>
</div>
</div>

<div class="reflow__item portrait">
<button type="button" class="lightbox_trigger" href="images/Image-002.jpg"><span class="glyphicon glyphicon-resize-full expand" title="Expand"></span></button>
<img src="images/Image-002.jpg" title="Image-002.jpg" alt="Image-002.jpg">
<div class="selection">
<label class="checkbox-inline 5x7" for="Image-002.jpg-5x7"><input class="5x7" type="checkbox" name="5x7[]" id="Image-002.jpg-5x7" value="Image-002.jpg" />5&times;7&middot;5 Prints</label>
<label class="checkbox-inline 8x12" for="Image-002.jpg-8x12"><input class="8x12" type="checkbox" name="8x12[]" id="Image-002.jpg-8x12" value="Image-002.jpg" />8&times;12 Prints</label>
</div>
</div>

<div class="reflow__item portrait">
<button type="button" class="lightbox_trigger" href="images/Image-003.jpg"><span class="glyphicon glyphicon-resize-full expand" title="Expand"></span></button>
<img src="images/Image-003.jpg" title="Image-003.jpg" alt="Image-003.jpg">
<div class="selection">
<label class="checkbox-inline 5x7" for="Image-003.jpg-5x7"><input class="5x7" type="checkbox" name="5x7[]" id="Image-003.jpg-5x7" value="Image-003.jpg" />5&times;7&middot;5 Prints</label>
<label class="checkbox-inline 8x12" for="Image-003.jpg-8x12"><input class="8x12" type="checkbox" name="8x12[]" id="Image-003.jpg-8x12" value="Image-003.jpg" />8&times;12 Prints</label>
</div>
</div>

<div>
<label for="Subject">Subject:</label><input type="text" placeholder="Print Selection - Bernadette &amp; Alexander" id="subject" name="subject" size="50" disabled>
</div>
<div>
<label for="name">Name:</label><input type="text" placeholder="Bernadette &amp; Alexander" id="name" name="name" value="Bernadette &amp; Alexander" size="50">
</div>
<div>
<label for="mail">Email:</label><input type="email" name="mail" id="mail" title="mail" placeholder="Your Email" size="80" required>
</div>
<div>
<input type="email" name="email" id="email" value="" placeholder="Valid Email" size="50" autocomplete="off" class="important">
</div>
<div class="submit-button">
<input type="submit" class="button" name="submit" id="submit" value="Submit">
</div>




Aucun commentaire:

Enregistrer un commentaire