SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    Apr 2003
    Location
    Rome
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    email () and arrays

    Hi!
    I need to input this code as a variable (the email_addrss field) in a
    <?php mail($email_addrss,$subject,$text) ?> statement but It continues giving me errors;

    ----
    <?php do { ?>
    <?php echo $row_Recordset1['email_ficha']; ?>
    ,
    <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
    ----



    Can anyone please help?

    Thank you very much!!!

    PS:
    Sorry I am quite a beginner...

  2. #2
    SitePoint Addict seanmayhew's Avatar
    Join Date
    Aug 2002
    Posts
    209
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Could you elaborate a little bit? What are you trying to accomplish? Also what errors are you receiving?

  3. #3
    SitePoint Member
    Join Date
    Apr 2003
    Location
    Rome
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually I need to email several users that are in a MySQL DB, so I need to fetch all the names from the DB and separate them with a comma (,) in order to use them as the first variable of a mail() statement.
    I was trying to do that with an array, but I think that's not the proper way to do it (also because it doesn't work! )!

    Thanks if you can give me any help!

  4. #4
    SitePoint Wizard Mike Borozdin's Avatar
    Join Date
    Oct 2002
    Location
    Edinburgh, UK
    Posts
    1,743
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this:
    PHP Code:
    <?
    while ( $row_Recordset1 mysql_fetch_assoc $Recordset1 ) ) {
      
    mail $row_Recordset["Email"], $subject$text ); //change the name of the fields to yours
    }
    ?>

  5. #5
    SitePoint Member
    Join Date
    Apr 2003
    Location
    Rome
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried to do it like this but now it seems to completely ignore the "if" statement which checks that the the submit button on the correct form is pressed and instead of displaying the form displays the "Email Sent!" msg...

    <?php
    if ($REQUEST_METHOD == "POST" && $sendemail == "ok") //this checks that the submit button on the correct form is pressed

    while ( $row_Recordset1 = mysql_fetch_assoc ( $Recordset1 ) ) {
    mail ( $row_Recordset1["email_ficha"], $subject, $text, "From: ftrends@ftrends.org"); //change the name of the fields to yours
    }

    {
    echo ( "<b><h2>Email Sent!</h2></b>" );
    exit();
    }
    ?>

    --------
    This below is the HTML code of the page in case you need it but i'm sure this is fine!
    --------

    <html>
    <head>
    <title>Enviar email por o curso <?php echo ( "$titolocurso_ficha" ); ?></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <body>

    <form name="form1" method="post" action="email_curso.php">
    <p>Subject:
    <input name="subject" type="text" id="subject">
    </p>
    <p>Textbr>
    <textarea name="text" cols="80" rows="20" id="text"></textarea>
    </p>
    <p>
    <input type="submit" name="Submit" value="Send Email">
    <input name="sendemail" type="hidden" id="email" value="ok">

    </form>
    </body>
    </html>
    <?php
    mysql_free_result($Recordset1);
    ?>

    Thanks!

  6. #6
    La la la la la bronze trophy lieut_data's Avatar
    Join Date
    Jun 2003
    Location
    Waterloo, ON
    Posts
    1,517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by giack
    I tried to do it like this but now it seems to completely ignore the "if" statement which checks that the the submit button on the correct form is pressed and instead of displaying the form displays the "Email Sent!" msg...
    PHP Code:
    <?php
    if ($REQUEST_METHOD == "POST" && $sendemail == "ok"//this checks that the submit button on the correct form is pressed

    while ( $row_Recordset1 mysql_fetch_assoc $Recordset1 ) ) {
      
    mail $row_Recordset1["email_ficha"], $subject$text"From: [email]ftrends@ftrends.org[/email]"); //change the name of the fields to yours
    }
     
    {
    echo ( 
    "<b><h2>Email Sent!</h2></b>" );  
    exit();
    }
    ?>
    Your above if statement is missing braces, thus the script executes mail regardless of whether or not the script was "posted". Try this:

    PHP Code:
    <?php

    if ($REQUEST_METHOD == "POST" && $sendemail == "ok") {
       while (
    $row_Recordset1 mysql_fetch_assoc ($Recordset1)) 
       {
          
    mail ($row_Recordset1["email_ficha"], 
                 
    $subject
                 
    $text
                 
    "From: [email]ftrends@ftrends.org[/email]"); 
       }
       echo ( 
    "<b><h2>Email Sent!</h2></b>" );  
       exit;
    }
    ?>
    My name is Steve, and I'm a super-villian.

  7. #7
    SitePoint Member
    Join Date
    Apr 2003
    Location
    Rome
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, this way It displays the form again, but It doesn't send any email...
    the emails should be fetched from the DB and separated by a comma... but the problem here is not the missing comma because I tryed this fetching only one address and it also didn't work...
    Does anyone have a better solution?
    Thanks again to everyone!


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
  •