Skip to main content
Inspiring
September 8, 2008
Question

URGENT PHP HELP

  • September 8, 2008
  • 12 replies
  • 575 views
I am working on a mail form that is linked to my payroll system. It is working great but there has been a request that I add a mail to all recipients feature. However I am not to sure how I would go about doing this, I am hoping someone can help me atler my current code. Right now the recipient selction is a drop down menu that is populated from a mySQL table within my payroll system.

I would like the first option when dropped down to be "All Recipents" so when it is sent the mail is sent to everyone's email not just the slected individual email.

Below is the current code I have where only one recipent can be selected.

Thanks in advance!

This topic has been closed for replies.

12 replies

Inspiring
September 11, 2008
I think you'll want to add a WHERE clause to the SQL statement

Example (check syntax):

$sql = mysql_query("SELECT user_email FROM user_info WHERE user_mail <>
''");

Notice that the end of the line has two single quotes and a double quote.
You would add the WHERE clause on both pages for the dropdown and for
building the To: string.

There's probably a slicker way to do this, depending on which database
you're using. You might want to use a LIKE statement to check that it exists
and resembles the correct format. or perhaps even more robust validation of
the e-mail address.


"bcounts" <webforumsuser@macromedia.com> wrote in message
news:ga7rhr$dci$1@forums.macromedia.com...
> That was the fix - worked great!
>
> Do either of you have any idea how to tell it to not populate the "to"
> with
> any user_email that is empty or " " (ie - the user did not enter an email
> account).
>
> Otherwise the script is going to fail since that is the way it is written.
>
> Also along the same lines how would I tell the drop down menu itself to
> only
> populate with users that have a user_email in the SQL table?
>
> This is my last question - I just want to make sure that there is no un
> needed
> information or users displayed.
>
> AGAIN THINK YOU SO MUCH! SAVED ME IN TIME OF NEED!
>


Inspiring
September 11, 2008
Probably a good thing, too. ;-)

"Mark A. Boyd" <lingoboyd@mboydDotcom.invalid> wrote in message
news:Xns9B157E6AE3084mblistssanDotrrcom@216.104.212.96...
> Steve posted in macromedia.dreamweaver.appdev:
>
>> Mark,
>>
>> No probably about it. Your example shows the correct way to
>> concatenate strings using assignment operators.
>
> Yea, no doubt about the concatenation. My "probably" was meant to mean
> that I didn't go through all the PHP to verify the rest of the
> statement.
>
>
> --
> Mark A. Boyd
> Keep-On-Learnin' :)


Inspiring
September 10, 2008
Steve posted in macromedia.dreamweaver.appdev:

> Mark,
>
> No probably about it. Your example shows the correct way to
> concatenate strings using assignment operators.

Yea, no doubt about the concatenation. My "probably" was meant to mean
that I didn't go through all the PHP to verify the rest of the
statement.


--
Mark A. Boyd
Keep-On-Learnin' :)
bcountsAuthor
Inspiring
September 10, 2008
That was the fix - worked great!

Do either of you have any idea how to tell it to not populate the "to" with any user_email that is empty or " " (ie - the user did not enter an email account).

Otherwise the script is going to fail since that is the way it is written.

Also along the same lines how would I tell the drop down menu itself to only populate with users that have a user_email in the SQL table?

This is my last question - I just want to make sure that there is no un needed information or users displayed.

AGAIN THINK YOU SO MUCH! SAVED ME IN TIME OF NEED!
Inspiring
September 10, 2008
Mark,

No probably about it. Your example shows the correct way to concatenate
strings using assignment operators.

I found this handy reference buried in a note at the bottom of
http://uk3.php.net/manual/en/language.operators.assignment.php:

Arithmetic
Operators( http://www.php.net/manual/en/language.operators.arithmetic.php)
Assignment Same as:
$a += $b $a = $a + $b Addition
$a -= $b $a = $a - $b Subtraction
$a *= $b $a = $a * $b Multiplication
$a /= $b $a = $a / $b Division
$a %= $b $a = $a % $b Modulus

String Operators
( http://www.php.net/manual/en/language.operators.string.php)
$a .= $b $a = $a . $b Concatenate

Bitwise Operators
( http://www.php.net/manual/en/language.operators.bitwise.php)
$a &= $b $a = $a & $b Bitwise And
$a |= $b $a = $a | $b Bitwise Or
$a ^= $b $a = $a ^ $b Bitwise Xor
$a <<= $b $a = $a << $b Left shift
$a >>= $b $a = $a >> $b Right shift


Thanks for catching that, Mark.


"Mark A. Boyd" <lingoboyd@mboydDotcom.invalid> wrote in message
news:Xns9B139147C332CmblistssanDotrrcom@216.104.212.96...
> Steve posted in macromedia.dreamweaver.appdev:
>
>> $to += $row1['user_email'] . ';';
>
> Probably should be:
>
> $to .= $row1['user_email'] . ';';
>
>
>
> --
> Mark A. Boyd
> Keep-On-Learnin' :)


bcountsAuthor
Inspiring
September 9, 2008
Thank you for your help thus far!

Can anyone else help me with this problem?
Inspiring
September 9, 2008
Bryan,

Sorry, but I don't have time to take on a programming assignment right now.
Perhaps one of the many folks in this forum can help you. To be honest, most
of them are better than I am anyway.

Good luck!

"bcounts" <webforumsuser@macromedia.com> wrote in message
news:ga46nq$2d$1@forums.macromedia.com...
>I kind of understand what you were trying to do here!
>
> I am at a loss because the coder that was doing this for us backed out and
> now
> the client is needing the change and I am not proficient enough in PHP to
> make
> the change.
>
> Ideally we would like the HTML and PHP to all be contained into one file
> and
> the validation handling to not be a print function but more of a $err=
> string.
> But right now I am mainly focused on getting the all recipients to work -
> I
> think because it is calling to another page on submit this is going to get
> confusing since the SQL database info in on the original mail.php.
>
> I have included a link to all the files making this mail form function - I
> was
> hoping you could take a look at it and maybe help us remedy the problem.
>
> We of course need the auth.php file not to be touched as it is the
> mainframe
> for the payroll system we are implanting this mail form into.
>
> However everything else that involves in the mail form can be altered and
> made
> into one or multiple PHP forms.
>
> Thank you in advance for your help and I look forward to learning
> something ?
> lol
>
> Link: www.bryancounts.com/mail.zip
>
> Bryan
>
>


bcountsAuthor
Inspiring
September 8, 2008
I kind of understand what you were trying to do here!

I am at a loss because the coder that was doing this for us backed out and now the client is needing the change and I am not proficient enough in PHP to make the change.

Ideally we would like the HTML and PHP to all be contained into one file and the validation handling to not be a print function but more of a $err= string. But right now I am mainly focused on getting the all recipients to work - I think because it is calling to another page on submit this is going to get confusing since the SQL database info in on the original mail.php.

I have included a link to all the files making this mail form function - I was hoping you could take a look at it and maybe help us remedy the problem.

We of course need the auth.php file not to be touched as it is the mainframe for the payroll system we are implanting this mail form into.

However everything else that involves in the mail form can be altered and made into one or multiple PHP forms.

Thank you in advance for your help and I look forward to learning something – lol

Link: www.bryancounts.com/mail.zip

Bryan
Inspiring
September 8, 2008
Steve posted in macromedia.dreamweaver.appdev:

> $to += $row1['user_email'] . ';';

Probably should be:

$to .= $row1['user_email'] . ';';



--
Mark A. Boyd
Keep-On-Learnin' :)
Inspiring
September 8, 2008
In your HTML code section, add a line for the "All Recipients" option:

Example:

<option value="">Select Recipients...</option>
<option value="all">All Recipients</option>

In your send_mail.php file, add some code after the second else statement to
figure out if the user selected All Recipients. If they did, loop through
the database and add the e-mail addresses to the $to string. Then just
execute the code that you already have.

Example:

if($subject == '') {print "You have not entered a subject, please go back
and
try again";}
else {
if($to == 'all')
{
$to = '';
$sql = mysql_query("SELECT user_email FROM user_info");
while ($row1 = mysql_fetch_array($sql))
{
$to += $row1['user_email'] . ';';
}
$send = mail($to, $subject, $body, $headers);
}
if($send)
{header( "Location: index.php" );}

I couldn't test this as I don't have your database or the "auth.php" file,
but I think that it is close. You'll also need to add your database
connection code to send_mail.php.



"bcounts" <webforumsuser@macromedia.com> wrote in message
news:ga2j6s$1i7$1@forums.macromedia.com...
>I am still a bit confused:
>
> The main question is how do I tell the script if the "All Recipients"
> option
> is selected to pull all the emails "user_email" from the user_info table
> in
> mySQL and send it to all of those people.
>