Page 1 of 1

Using PHP's mail for Multple Posted Email Addresses - how?

Posted: Sun Jul 26, 2009 11:32 am
by simonmlewis

Code: Select all

$to = "".$_POST['email1'] . "," . $_POST['email2'] . "," . $_POST['email3'] . "," .$_POST['email4'] . "," .$_POST['email5'];
Hi.
I am building a "tell a friend" system, and want to give the user the option to tell up to 5 friends.

But... this isn't working and I am sure it's because of this part of the code.

Surely I don't have to do 5 IF statements based on whether email2 != NULL, or email3 !=NULL etc...??

It's probably an easy one to answer but I can't work it out.

Re: Using PHP's mail for Multple Posted Email Addresses - how?

Posted: Sun Jul 26, 2009 11:42 am
by insight
simonmlewis wrote:

Code: Select all

$to = "".$_POST['email1'] . "," . $_POST['email2'] . "," . $_POST['email3'] . "," .$_POST['email4'] . "," .$_POST['email5'];
Hi.
I am building a "tell a friend" system, and want to give the user the option to tell up to 5 friends.

But... this isn't working and I am sure it's because of this part of the code.

Surely I don't have to do 5 IF statements based on whether email2 != NULL, or email3 !=NULL etc...??

It's probably an easy one to answer but I can't work it out.
It probably is from that part of the code. I have never successfully been able to send stuff to multiple emails at once. An easy way to find out if it works or not is by replacing the ".$_POST['email']." (all five of them) with an actual email. If it works then there must be a problem with the $_POST you have written there.

Re: Using PHP's mail for Multple Posted Email Addresses - how?

Posted: Sun Jul 26, 2009 11:54 am
by globezone
This should help you.

Code: Select all

 
<?php
$can_continue = false;
 
for($i=0; $i<count($tell_a_friend); $i++)
{
    if(!empty($tell_a_friend[$i]) || $tell_a_friend != "")
    $can_continue = true;
}
 
if($can_continue)
{
    $_needle = array();
    
    for($j=0; $j<count($tell_a_friend); $j++)
    {
        if(!empty($tell_a_friend[$j]) || $tell_a_friend[$j] != "")
        {
            $_needle[] = $tell_a_friend[$j];
        }
    }
    
    echo "<pre>";
    var_dump($tell_a_friend);
    
    echo "<br />";
    
    var_dump($_needle);
    echo "</pre>";
}
 
?>
 
<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <input type="text" name="tell_a_friend[]" /> <br />
    <input type="text" name="tell_a_friend[]" /> <br />
    <input type="text" name="tell_a_friend[]" /> <br />
    <input type="text" name="tell_a_friend[]" /> <br />
    <input type="text" name="tell_a_friend[]" /> <br />
    <input type="submit" />
</form>
 
 

[RESOLVED]Re: Using PHP's mail for Multple Posted Email A...

Posted: Sun Jul 26, 2009 12:46 pm
by simonmlewis
It turns out it DID work - the server was just terribly delayed.

So no need for the length code from globe (but thanks).
Basically, if there in an email in each variable, it'll pass it. If there isn't, it just sends it to those where there is an occupied variable.

Simple.

And it works better than the tellafriends you can use from free sites. I tried one yesterday and it never even sent the email!