tedbg tedbg - 13 days ago 5
PHP Question

Warning: implode() [function.implode]: Invalid arguments passed in

Hi I already checked all the posts with the same title but none helps me. First of all I'm a complete newbie and trying to make sendmail.php to get the information from short contact form I got a premade script and try to add a checkbox but not sure how to grep and send is the box checked or not and send to email.

This is the script:

$to="admin@email.com";/*Your Email*/
$subject=$_REQUEST['subject'];

$date=date("l, F jS, Y");
$time=date("h:i A");

$firstName=$_REQUEST['name'];
$email=$_REQUEST['email'];
$phone=$_REQUEST['phone'];
$hosting = (implode(',', $_POST['hosting']));


$msg=" Message from contact form sent: $date, hour: $time.\n
Име: $firstName\n
Email: $email\n
Телефон: $phone
Хостинг: ".$hosting."\r\n
";



if($email=="") {
echo "<div class='alert alert-danger'>
<a class='close' data-dismiss='alert'>×</a>
<strong>Warning!</strong> Fill all boxes.
</div>";
} else {
mail($to,$subject,$msg,"From:".$email);
echo "<div class='alert alert-success'>
<a class='close' data-dismiss='alert'>×</a>
<strong>Will contact with you.</strong>
</div>";
}


And this is the part of the contact form code :

input type="checkbox" name="hosting[]" value="Get Hosting"


See:


Answer

I am not sure what you need in the variable hosting or why you define the input tag as an array when there is only one value available. You should use

<input type="checkbox" name="hosting" value="Get Hosting">

in your form and can use this instead of implode

$hosting = isset($_POST['hosting']) ? $_POST['hosting'] : 'No Hosting';

It will write "Get Hosting" if the checkbox is set and "No Hosting" if not.

Sincerly