1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Why dosn't this php script work?

Discussion in 'PHP & Perl' started by howdoyou, Nov 13, 2009.

  1. howdoyou

    howdoyou Regular Member

    Joined:
    Nov 17, 2008
    Messages:
    284
    Likes Received:
    57
    Occupation:
    Programming
    Location:
    Kentucky
    Code:
    <?php
    $subject = "Hi!";
    $body = "Hi,\n\nHow are you?";
    $from = "From: test@test.com";
    $arr = array("email1@hackermail.com", "email2@hackermail.com", "email3@hackermail.com");
    reset($arr);
    foreach ($arr as $to) {
        echo "To: $to<br />\n";
        if (mail($to,$subject,$body,$from)) {
            echo("<p>Message successfully sent!</p>");
         } else {
            echo("<p>Message delivery failed...</p>");
         }
        sleep(3);
    }
    ?>
    
    
     
  2. ccpro

    ccpro Junior Member

    Joined:
    Jul 28, 2008
    Messages:
    115
    Likes Received:
    522
    Occupation:
    cookie stuffing
    Location:
    in your cookie bin
  3. ashok

    ashok Regular Member

    Joined:
    Mar 23, 2009
    Messages:
    402
    Likes Received:
    143
    your script seems correct,,, it should work
     
  4. XoC--

    XoC-- Jr. VIP Jr. VIP Premium Member

    Joined:
    Mar 5, 2009
    Messages:
    211
    Likes Received:
    113
    Are you receiving any errors? It should work like that however you could always change the headers to
    Code:
    "From: Test <test@test.com>"
    Also make sure to check your spam folder as it may not be hitting the inbox
     
  5. aмillionaírе

    aмillionaírе Jr. VIP Jr. VIP Premium Member

    Joined:
    Apr 20, 2008
    Messages:
    532
    Likes Received:
    358
    PHP:
    foreach ($arr as $to)
    Echo $to to make sure it is the actual array instead of the array key (which is by default a number). Weird, but sometimes I have to put
    PHP:
    foreach($arr[0] as $x)
    in some of my scripts.

    This is all determined by the way your arrays are generated (preg, explode, etc.).


    Why are you using the reset function? Is that needed? Comment that out, echo $to, and re-execute the script. See what happens. The foreach command takes care of each array value.
     
    Last edited: Feb 11, 2010