Now I have another issue. Using the form that I created it is possible to send either to ALL or to specific recipients.
If sending to ALL, then the above code works nicely.
But in the case of select recipients I have not figured out a way to go through the array and select one recipients email at a time, add it to the $to and then continue going through the array until its finished.
This is what I have been trying, but it's not working:
PHP Code:
for ( $i=0; $i < count($recipients); $i++ ) {
$prename = $recipients[$i];
$content = mysql_query("SELECT email FROM users where username=$prename");
there are a few ways to do this,
personally, I'd prefer to set the option value to a user id then in the mail script run a select to get the username and email.
alternatively, you could do just a delimiter in the value like:
So I end up with an Array of usernames in $_GET['recipients']
So I need a step to get each username, obtain the email for it and add it to $to.
Or is there an easier method? I have the feeling I am complicating things?
I think you might mean to say that you have an array of results in $recipients = $_POST['nform_newslrecipients'];
Is the form code you entered the actual code from the page or just a rough estimation? If it's not copy/pasted from your actual page please update it to be the actual code.
Under normal circumstances select boxes will return only one value (the one the user chose), not every value in the select box. If you are getting an array of results then something is not being done as it should. If your code truly does read as above then I believe your only issue is that the name used for the select element has brackets "[]" behind it. I have never played around with that method, but my understanding is that this indicates to the browser that this element will return multiple values (so the browser returns multiple values).
Try removing those brackets and see if you get only one entry for the select element.
pretty sure it's to have an array of elements. Do you have multiple dropdowns of usernames and you select them with those? Checkboxes would definitely be a better choice IMO
Try removing those brackets and see if you get only one entry for the select element.
I think that maybe you've missed the point, he wants the array ( though yes, you can only get one value from a normal select, but he's likely use a multi ), he just needs a way to get both the persons name in email in one shot.
I think that maybe you've missed the point, he wants the array ( though yes, you can only get one value from a normal select, but he's likely use a multi ), he just needs a way to get both the persons name in email in one shot.
Which is some of the source of my confusion. That's why I'm asking for a solid copy/paste from the code. Otherwise, using the brackets without using a multi select will (I believe) return all results in the select. I might be totally wrong about that.
Then again, as I said, I've never really toyed with this specific issue so I'm half guessing at a lot of it which probably isn't the most productive thing in the world to do.
Quote:
Originally Posted by JAY6390
Also, like it's been said above you need to have a value for your selects...
For the <option> tags, actually but yes, values certainly do need to be inserted here.
also, without the multi, only one value would still be returned. but who knows, maybe he has a few of these single selects on one page. I *believe* that would still return the same result as a multi.
I wrote a simple newsletter/emailing feature. In the form the user can choose to send to:
ALL
or
select recipients
the form pulls all usernames from the db who have chosen to receive a newsletter and displays them in a <select multiple="multiple"> box.
Here is the complete code for the form (i have since added the email as a value for the <option>'s:
PHP Code:
<h2>Write Newsletter</h2> <?php
if ($_SESSION['username'] == "admin" && $_SESSION['logged_in'] == 1) {
//include our db data to make the connection include ('db.php');
if ($_SESSION['newsl_error'] == 1) { echo 'You cannot select <b>ALL</b> and <b>specific</b> users, select either one or the other<br /><br />'; unset($_SESSION['newsl_error']); }