0

I'm really struggling to find a way to send checklist data to an email, let alone a user input email! I have tried following and applying the answers from other similar questions asked but still to no avail.

This is my PHP so far, although I am quite confused.

<?php 
//Check for POST
if (isset($_REQUEST['email'])){
//All your inputs
$expecting = array('checkbox1','checkbox2','checkbox3','checkbox4' ,'checkbox5');

//Start building your email
$email_content = '';
foreach($expecting as $input){
    //Is checkbox?
    if(substr($input,0,8)=='checkbox'){
        $email_content .= ucfirst($input).':'.(isset($_POST[$input]) && $_POST[$input] == 'on' ? 'True' : 'False'.'<br />');

    }else{
        $email_content .= ucfirst($input).':'.(!empty($_POST[$input]) ? $_POST[$input] : 'Unknown').'<br />';
    }
}
print_r($email_content);


if(mail('$email',  'packing list', wordwrap($email_content))){
   //mail sent
}else{
   //mail failed 2 send
}

}
?>

And this is my HTML

  <form name="emailform"  method="post" action="send-list.php">
  <div data-role="fieldcontain">
  <label for='name'><h3>Festival name:</h3> </label>
  <input type="text" name="name"> 



<h3>
Essentials
</h3>

<fieldset data-role="controlgroup" data-type="vertical">
<legend>
</legend>
<input name="checkbox1" id="checkbox1" type="checkbox" />
<label for="checkbox1">
Tickets
</label>
<input name="checkbox2" id="checkbox2" type="checkbox" />
<label for="checkbox2">
Parking pass
</label>
<input name="checkbox3" id="checkbox3" type="checkbox" />
<label for="checkbox3">
Directions
</label>
<input name="checkbox4" id="checkbox4" type="checkbox" />
<label for="checkbox4">
Cash &amp; Cards
</label>
<input name="checkbox5" id="checkbox5" type="checkbox" />
<label for="checkbox5">
Keys
</label>
</fieldset>

Email: <input name='email' type='text'><br>
<input type="submit" value="Send">

I would be happy if I could just get the checked boxes to send to an email and from there, I would hopefully be able to work out how to send the information to a user input email.

2
  • 1
    Is there a form tag in you html? Commented Jan 28, 2013 at 16:29
  • It doesn't come up with an error. Instead it says "loading" underneath for some reason. I guess that's my JQuery Mobile.. Commented Jan 28, 2013 at 16:42

2 Answers 2

2

You're doing it mostly right, but your code is checking of the checkboxes have the value "on"... but never set that value in your form:

<input name="checkbox5" id="checkbox5" type="checkbox" value="on" />
                                                       ^^^^^^^^^^

This is also a syntax bug:

if(mail('$email',  'packing list', wordwrap($email_content))){
        ^--    ^--

single-quoted strings do NOT interpolate variables. so you're trying to send an email to an account named $email, not whatever address is in the $email variable.

Try

if(mail($email,  'packing list', wordwrap($email_content))){

instead (note lack of quotes).

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

Comments

0

The $email variable is not defined.

Put this:

  $email = $_REQUEST['email'];

before the mail function call, and use mail($email, ... for it to work.

1 Comment

You have to use mail($email, ...) for your example to work, single quotes do not evaluate variables.

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.