ETA: Someone marked this question as duplicate, but I have combed all of the similar threads and nothing suggested has worked. Adding brackets (as in need[]
) did not work - it returns the exact same result as discussed below. If I could have found the answer in another thread, I would not have made a new one. It required me to register for an account and spend time formatting a post, which is time I would have spent working on this website if the answer was already posted here.
If you have an example of a thread with a solution that might work, feel free to link to it, but I have looked at every thread I could find on this website that even remotely seemed related. Thanks.
I've seen this answered several times in several ways, but none of the solutions have worked for my situation, so I'm posting here in hopes that someone can help.
The website is a landing page where prospective clients will fill out a form, which will then be sent to a specified email address. The form contains ten checkboxes of services they, all formatted thus:
<input type="checkbox" name="need" value="svc3">Description of Service 1<br/>
<input type="checkbox" name="need" value="svc2">Description of Service 2<br/>
<input type="checkbox" name="need" value="svc3">Description of Service 3<br/>
And so on and so forth, for 10 options. Any/all options should be able to be selected. In the email handler PHP file, I have this code:
$name = $_POST['name'];
$email_address = $_POST['email'];
$location = $_POST['loc'];
$age = $_POST['age'];
$gender = $_POST['gender'];
$need = implode(", ", $_POST['need']);
(I originally used just $need = $_POST['need'];
but that only provided the last selected variable, not all selected variables.)
$to = $myemail;
$email_subject = "New Consultation Request: $name";
$email_body = "You have received a new request for a FREE consultation. \n".
"Name: $name \nEmail: $email_address \nLocation: $location \nAge: $age. \nGender: $gender \n".
"\nI would like to work on: $need \n"
"\nMessage: \n$message ";
$headers = "From: $myemail\n";
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
Everything else sends perfectly. Currently, the email sends with no data in the $need
field, as such:
You have received a new request for a FREE consultation.
Name: Mr. Robot
Email: fake@mail.com
Location: Mars
Age: 100
Gender: Robot
I would like to work on:
Message:
Hello, I am a test. Robot voice.
What am I doing wrong?