Jump to content

problem retrieving data from a form (send a email to selected people)


arbitter

Recommended Posts

I want this simple php form which allows me to send mails to all of my contacts or all of my selected contacts.

 

This is what I have:

<html>
<?php

if(isset($_POST['actie']))
{echo 'actie';
$persoon = $_POST['persoon'];
echo $persoon;


exit();
}

?>


<form method="post" action="mail.php">
<b>Recipients:</b><br>
<input type="checkbox" name="person" value="Everybody">Everybody<br>
<?php
require_once('mysql_connect.inc.php');
mysql_connect(MYSQL_SERVER, MYSQL_GEBRUIKERSNAAM, MYSQL_WACHTWOORD) or die("Verbinding mislukt: " . mysql_error());
mysql_select_db("users") or die("Couldnt open: " . mysql_error());
$query  = "SELECT name, email FROM users";
$result = mysql_query($query)or die(mysql_error());
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
    echo "<input type='checkbox' name='persoon' value='" . $row['email'] . "'>" . $row['name'] . "<br>";
} 

?>

<b>Message:</b><br>
<textarea rows="5" cols="20" name="message">

</textarea><br>
<input type="submit" value="Email Myself" name='actie'>
</form>

</html>

 

 

Now, part of this is already working; I want to get a list of all my contacts, and I do indeed get a list of all my contacts With the php part where I connect with my database.

 

The problem is, that I need to get all the data of the 'person' part in the form. I need all of the emails (that I selected), because I need to send my mail to all of them.

 

Anyone a little help?

Link to comment
Share on other sites

Your query is only retrieving NAME and EMAIL, so that's the only data that you can display in your form. Right now you only display NAME. If you want to display NAME and EMAIL do this:

echo "<input type='checkbox' name='persoon' value='" . $row['email'] . "'>" . $row['name'] .' '.$row['email'] "<br>";

 

Link to comment
Share on other sites

Yes, I am aware of that. But I don't need to display the email.

 

I have the checkboxes, with a value of an email. Next to the checkbox it gives the name of the person who's email it is, so I can see whom I'd like to send it to.

 

Now, when I click the submit button, the message should be sent to all selected recepients, or if I click everybody, to everybody. How do I do that?

 

For the textarea;

<?php $message = $_POST['message'];
$message = strip_tags($message);
$message = trim($message);?>

 

But for the checkboxes, $_POST['person'] ,can only give one result? Or how does this work?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.