SitePoint Sponsor

User Tag List

Results 1 to 25 of 25
  1. #1
    SitePoint Enthusiast til's Avatar
    Join Date
    Aug 2004
    Location
    uk
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    mail in a loop :(

    i have tried this....

    <?
    $conn=mysql_connect(mysql connection info);
    $db = mysql_select_db("test");
    $emails = mysql_query("SELECT * FROM users where 1");
    while($row = mysql_fetch_array($emails)) {

    $subject = "test";
    $message = "test";
    $email = $row["email"];

    mail($email, $subject,
    $message, "From:Your name <you@whatever.com>");

    }
    ?>

    but php just hangs , theres nothing wrong with my mysql database and I can loop out the email addresses and echo them fine.....

    If i put mail("some1@somewhere.com", "hi",
    "test", "From:Your name <you@whatever.com>");
    inside the while() loop php hangs even then, if its outside the loop it works fine.... this is weird, any ideas?

  2. #2
    SitePoint Guru augathra's Avatar
    Join Date
    Jul 2004
    Location
    united states
    Posts
    826
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    is anything actually being returned by the query? If not, the loop won't be run.

  3. #3
    SitePoint Guru augathra's Avatar
    Join Date
    Jul 2004
    Location
    united states
    Posts
    826
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry for double posts, but try this:

    PHP Code:
    $conn=mysql_connect(mysql connection info);
    $db mysql_select_db("test");
    $emails mysql_query("SELECT * FROM users where 1");
    while(
    $row mysql_fetch_array($emails)) {
    $email $row['email'];
    }
    if(empty(
    $email) {
     echo 
    "empty email";
    } else {
    mail($email$subject$message"From:Your name <you@whatever.com>");


  4. #4
    SitePoint Enthusiast til's Avatar
    Join Date
    Aug 2004
    Location
    uk
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ooo, shoved echo "email sent"; in there, but still no luck :'(

  5. #5
    SitePoint Enthusiast til's Avatar
    Join Date
    Aug 2004
    Location
    uk
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oo thanks for the code, but php still hangs

  6. #6
    SitePoint Guru augathra's Avatar
    Join Date
    Jul 2004
    Location
    united states
    Posts
    826
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Change this: $db = mysql_select_db("test"); to mysql_select_db("test");

  7. #7
    SitePoint Enthusiast til's Avatar
    Join Date
    Aug 2004
    Location
    uk
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ahhh, php.stillhanging = true

  8. #8
    SitePoint Guru augathra's Avatar
    Join Date
    Jul 2004
    Location
    united states
    Posts
    826
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by til
    ooo, shoved echo "email sent"; in there, but still no luck :'(
    What do you mean, "email sent"? Is there more to the script? If so can you post it all. It may not be neccessary but there may be a small piece destroying it all.

  9. #9
    SitePoint Enthusiast til's Avatar
    Join Date
    Aug 2004
    Location
    uk
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    errmmm, i just added the string echo "email sent", so the entire script looks like this..


    Code:
    <?
    $conn=mysql_connect(mysql database info);
    mysql_select_db("test");
    $emails = mysql_query("SELECT * FROM users where 1");
    while($row = mysql_fetch_array($emails)) {
    $email = $row['email'];
    }
    if ($email=="") {
    echo "empty email";
    } else {
    echo "email sent";
    mail($email, $subject, $message, "From:Your name <you@whatever.com>");
    } 
    ?>

  10. #10
    SitePoint Guru augathra's Avatar
    Join Date
    Jul 2004
    Location
    united states
    Posts
    826
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try this in another page.
    $email = 'a_test_email@hotmail.com'; // use an address you can check //
    $subject = 'Wat up dawg';
    $message = 'Hey dawg, watcha doing tnight?';

    if(mail($email, $subject, $message)) {
    echo "teh email has been sent!";
    }

    Just temporarily.

  11. #11
    SitePoint Enthusiast til's Avatar
    Join Date
    Aug 2004
    Location
    uk
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hanging

  12. #12
    SitePoint Guru augathra's Avatar
    Join Date
    Jul 2004
    Location
    united states
    Posts
    826
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not an advanced PHP programmer, but you must have a PHP setting stopping this, or you have script before the mail() which is stopping it.

    I used the following code, and only the following code, and I recieved the email.
    PHP Code:
    $email 'myemail.mysite.com'// use an address you can check //
    $subject 'Wat up dawg';
    $message 'Hey dawg, watcha doing tnight?';

    if(
    mail($email$subject$message)) {
    echo 
    "teh email has been sent!";

    Therefore, the settings on my site must be different than yours, or you are doing something before the script. If it's the settings, another more experienced programmer will have to assist you.

  13. #13
    SitePoint Enthusiast til's Avatar
    Join Date
    Aug 2004
    Location
    uk
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok thanks a lot

  14. #14
    SitePoint Enthusiast til's Avatar
    Join Date
    Aug 2004
    Location
    uk
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i dunno if this helps at all, but i can do mail(whatever email info here) and it works fine

  15. #15
    SitePoint Guru augathra's Avatar
    Join Date
    Jul 2004
    Location
    united states
    Posts
    826
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I see, yes it does help. Can you make another file, and copy & paste this in it, *do not edit anything*. Do not add a header, <html> or anything. Go the address once you have uploaded it.

    $email = 'rpg_1@hotmail.com';
    $subject = 'Wat up dawg';
    $message = 'Hey dawg, watcha doing tnight?';

    if(mail($email, $subject, $message)) {
    echo "The email has been successfully sent! Hurrah";
    } else {
    echo "The email was not sent. Arg!";
    }

  16. #16
    SitePoint Enthusiast til's Avatar
    Join Date
    Aug 2004
    Location
    uk
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ahhh its a problem with something... mail () no longer works at all

  17. #17
    SitePoint Guru augathra's Avatar
    Join Date
    Jul 2004
    Location
    united states
    Posts
    826
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm, I probably can't help then. Also make sure your using the .php extension.

  18. #18
    Non-Member Icheb's Avatar
    Join Date
    Mar 2003
    Location
    Germany
    Posts
    1,474
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    augathra: Good to know. Why is that? He could use .princeofengland for all he cares, as long as that file gets parsed as PHP.

  19. #19
    SitePoint Guru augathra's Avatar
    Join Date
    Jul 2004
    Location
    united states
    Posts
    826
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, it was my mistake, I should have said "make sure you files are getting parsed as PHP". I made an assumption he was using .php. Once in a while my editor will save files as .htm when I was working on PHP files. This would cause an error normally.

  20. #20
    SitePoint Enthusiast til's Avatar
    Join Date
    Aug 2004
    Location
    uk
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    using .php

  21. #21
    SitePoint Enthusiast til's Avatar
    Join Date
    Aug 2004
    Location
    uk
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    LOL - just got 60 emails in my mail box from what ive been playing with!! -- it looks like its sending the emails when i stop the firewall - i should be able to fix it now

  22. #22
    SitePoint Enthusiast til's Avatar
    Join Date
    Aug 2004
    Location
    uk
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ooooooook its not when i turn off the firewall
    i dunno, could it be queueing the emails and then sending them later on?? my server is red hat 9... any ideas?

  23. #23
    SitePoint Guru augathra's Avatar
    Join Date
    Jul 2004
    Location
    united states
    Posts
    826
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Did you copy & paste the code I showed above? I never received an email (rpg_1@hotmail.com)?

  24. #24
    SitePoint Enthusiast til's Avatar
    Join Date
    Aug 2004
    Location
    uk
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yeah i changed it to my email

  25. #25
    SitePoint Enthusiast til's Avatar
    Join Date
    Aug 2004
    Location
    uk
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    SORTED!!!! wooooooooooo for some reason the firewall blocking port 25 was stopping the mail, which i guess makes sense although it never used to.. anyway thanks guys!! -


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •