Quoting Aaron Wolski <[EMAIL PROTECTED]>:
> Hi All,
>
> Trying to create a "refer a friend" script.
>
> User enters 10 names and email address of a friend to refer to a site.
>
> The following code SORT of works in that it will send the email, etc..
> but problem is it duplicates - sends the email out twice to the same
> email address.
>
> **CODE***
>
> foreach($nameRefered as $referedName) {
>
> foreach($emailRefered as $referedEmail) {
>
> if ($referedEmail != "" && $referedName != "") {
>
> <message body here>
>
> /* To send HTML mail, you can set
> the Content-type header. */
> $headers = "Return-Path:
> <$support_email>\r\n";
> $headers .= "MIME-Version: 1.0\r\n";
>
> $headers .= "Content-type:
> text/html; charset=iso-8859-1\r\n";
> $headers .= "From: $nameReferer
> <".$emailReferer.">\r\n";
>
> mail ($referedEmail,"Your Order on
> Rinkrake.com", $message, $headers);
>
> }
> }
> }
>
> Any thoughts on why I get the email twice?
>
> Thanks all. Much appreciated!
>
> Aaron
Lemmie, try that again, (darn webmail and TABS moving to next form element)...
FYI - prob. better in the php-general list.
But, I think your nested foreach() are the culprit.
Assuming $nameRefered = (
'Joe',
'Bob',
'Jane'
)
Assuming $emailRefered = (
'[EMAIL PROTECTED]',
'[EMAIL PROTECTED]',
'[EMAIL PROTECTED]'
)
With your code, you would get emails to the following...
Joe <[EMAIL PROTECTED]>
Joe <[EMAIL PROTECTED]>
Joe <[EMAIL PROTECTED]>
Bob <[EMAIL PROTECTED]>
Bob <[EMAIL PROTECTED]>
Bob <[EMAIL PROTECTED]>
Jane <[EMAIL PROTECTED]>
Jane <[EMAIL PROTECTED]>
Jane <[EMAIL PROTECTED]>
I would consider using the following due to the name/email being stored in
separate variable structures.
for( $i=0, $i < sizeof($nameRefered), $i++){
/* to get this name */
$thisname = $nameRefered[$i];
/* to get thisname's email */
$thisemail = $emailRefered[$i];
}
Provided of course that the values in the slots of the array correspond perfectly.
--
Ryan T. Gallagher
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php