SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Jun 2001
    Location
    Malaysia
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    darn " " in the mail() function

    hey guys!

    OK.. this might seem dumb, but here goes. I have a list of email address, stored in a database.

    I would like to call out an email address, assign it to a variable and plug it into a mail() function so it can send off a mail.

    What I've done so far is something like this:

    $sql = "SELECT EMAIL FROM PDC_EMP
    WHERE WWID = 10662106 ";
    echo $sql; // for debugging purposes
    mysql_query($sql);

    mail($sql, $subject, $message, $headers);

    I have $subject, $message, $headers defined, so that part works.

    What concerns me is the $sql. I note that $sql will return an email address (eg: nobody@nobody.com). I note that you need to plug in an email address, COMPLETE with the " " quotes, so the function should read:

    mail("nobody@nobody.com", $subject, $message, $headers);

    The above would work fine. Problem is, the $sql var. only returns an email address, minus the " ". How do I make it so that the email add. comes complete with the " "? PHP issues a "Warning: Bad Message Destination" when I call:

    mail($sql, $subject, $message, $headers);

    I think it's because of the " " that needs to encapsulate the email address. I've tried assigning a single " to a variable, and then calling something like:

    mail ($open_comma $sql $close_comma, $message, $headers);
    so the mail function would look like
    mail("nobody@nobody.com", $subject, $message, $headers);

    Get it so far? Yeah. anyway... so....any ideas? I've stopped short of assigning a " " to each of my database EMAIL entries..

    FreakySid.. where are ya??! Would greatly appreciate your input!

  2. #2
    SitePoint Enthusiast Ckeren's Avatar
    Join Date
    Jun 2001
    Location
    AU
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try this:

    PHP Code:
    $sql "SELECT EMAIL FROM PDC_EMP WHERE WWID = '10662106' "

    if(!
    $result mysql_query($sql)) // for debugging purposes 
       
    die("Invalid WWID! Error= " .mysql_errno());
    else
    {
       
    $row mysql_fetch_array($result);
       
    $mail "\"$row[0]\"";
       
    //Testing print out if mail format is okay
       
    print "Is mail format like this: $mail";

    the \" to tell php as that is part of the text or data

  3. #3
    Node mutilating coot timnz's Avatar
    Join Date
    Feb 2001
    Location
    New Zealand
    Posts
    516
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As Ckeren demonstrated, you actually need to fetch the results before you can use them. Your $sql is a result identifier I think is what you call it. What mysql_query does is query the database, and then you can use mysql_fetch_array or mysql_result or mysql_fetch_row to actually get the data out of the database for us.

    $mail = "\"$row[0]\"";
    If you have the quotes already in the mail function.
    It should only need to read:
    $mail = "" . $row[0] . "";
    As that should evaluate to
    $mail = "email@email.com";

    You need to get out of the quotes demonstrated by the " and . because otherwise [0] will be taken literally I THINK at least, correct me if I'm wrong.

    So
    mail("$mail", $subject, $message, $headers);

    Would work in this case, other wise Ckeren's $mail variable would work in this case:
    mail($mail, $subject, $message, $headers);

    I think I've just gone round in many a circle

  4. #4
    SitePoint Addict
    Join Date
    Jun 2001
    Location
    Malaysia
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Ckeren
    try this:

    PHP Code:
    $sql "SELECT EMAIL FROM PDC_EMP WHERE WWID = '10662106' "

    if(!
    $result mysql_query($sql)) // for debugging purposes 
       
    die("Invalid WWID! Error= " .mysql_errno());
    else
    {
       
    $row mysql_fetch_array($result);
       
    $mail "\"$row[0]\"";
       
    //Testing print out if mail format is okay
       
    print "Is mail format like this: $mail";

    the \" to tell php as that is part of the text or data
    yes.. that worked PERFECTLY! Thanks guys.... Timnz.. your explanation made sense.. i see the Light now...


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
  •