0

sorry, I have another problem now. I'm using a new php form method than I previously used.

I have something like this:

<?php 
$ToEmail = '[email protected]'; 
$subject = 'Contact Form'; 
$mailheader = "From: ".$_POST["email"]."\r\n"; 
$mailheader .= "Reply-To: ".$_POST["email"]."\r\n"; 
$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n"; 
$message = "Name: ".$_POST["name"]."<br>"; 
$message .= "Subject: ".$_POST["subject"]."<br>"; 
$message .= "Email: ".$_POST["email"]."<br>"; 
$message .= "Message: ".nl2br($_POST["message"])."<br>"; 
mail($ToEmail, $subject, $message, $mailheader) or die ("Failure"); 

but I need to include check boxes. I originally had: $check .= implode(', ', $_POST['check']); from someone else on here but that doesn't work now and not sure what else to do for this. Any help would be appreciated!

the page is located here: http://makeupbysherry.com/contact.php

2 Answers 2

1

Checkboxes only post a true or false value if they're checked or not. I would suggest breaking up each of your checkboxes with unique names then checking their post values.

input name="chk-makeover" value="Makeover" type="checkbox" class="contact_checkbox"

To include the example checkbox above in your message you can try the following:

$message .= "Services: ";
if (isset($_POST['chk-makeover'])) $message .= "Makeover";

Sign up to request clarification or add additional context in comments.

1 Comment

How would I display that in the php part like in the code above?
0

You want to append the selected boxes onto your message?

Your $check .= implode(', ', $_POST['check']) should work, all you have to do to that is append it to the message afterwards.

So:

<?php 
$ToEmail = '[email protected]'; 
$subject = 'Contact Form'; 
$mailheader = "From: ".$_POST["email"]."\r\n"; 
$mailheader .= "Reply-To: ".$_POST["email"]."\r\n"; 
$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n"; 
$message = "Name: ".$_POST["name"]."<br>"; 
$message .= "Subject: ".$_POST["subject"]."<br>"; 
$message .= "Email: ".$_POST["email"]."<br>"; 
$message .= "Message: ".nl2br($_POST["message"])."<br>";

if(isset($_POST['check'])){
    $message .= implode(', ', $_POST['check']);
}

mail($ToEmail, $subject, $message, $mailheader) or die ("Failure"); 

Edit: Forgot the check to see if the check array that's sent through POST is set or not. See revised ^^

Edit2: Actually, there'll be a problem if the $_POST['check'] doesn't exist as we are still appending from $check that doesn't have anything on the next line so, so it's better to append it to $message right from the start. Last revision lol. Good luck.

5 Comments

It worked but had the Array in front of the checkbox option. I'll try the revise. Thanks!
Ok hehe, that last one didn't come through guess it didn't work? On goDaddy it went super fast. On Netsol it takes like 5-10 minutes to get a message
A good way to check if the mail is being sent in the first place is to echo it out. the mail function in php actually returns a boolean value (true/false) so it's a nifty check. Also you can echo the $message to see if the string is being constructed correctly.
As you can tell, I'm clueless with php haha. I wouldn't know what to do. But appreciate your help. I've been pulling my hair out tonight on this. Not sure this worked or not since the email didn't come through
Things can take time ^^ the mail function check is just a debugging thing, so it's not really needed unless you need to specifically check to see if the mail is sent but the die('Failure') should tell you if the mail function failed.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.