SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Addict
    Join Date
    Sep 2000
    Location
    Ontario, Canada
    Posts
    320
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm taking input from a form for a "send this link to a friend" sort of thing where the person on the site enters in a little message and the link is then added in by the script.

    What I'd like to do is send the link owner an email when someone forwards their site to a friend.

    Sending the link to a friend works, but its the other part that's causing the problem.

    Here's what I have so far and its just not sending a message:

    PHP Code:
    $result mysql_query("SELECT * FROM agents WHERE id='$aid';",$link);
    while (
    $a_row =mysql_fetch_array ($result))
    {
    $agentto=$a_row[agentemail];
    $agentsubject="Listings Information Requested";
    $agentmessage="$to was forwarded information on";
    }

    mail($agentto$agentsubject$agentmessage"From: ".$fromName." <".$fromAddress.">") or print "Could not send mail.<BR><HR><BR><P>"
    Basically, $aid is passed from a link to the sendtoafriend.php page. The database looks to the database for the corresponding email address and "should" send them a message -- but it doesn't.

    ($fromname/$fromaddress are defined in an included file)

    Any suggestions are greatly appreciated!

    thanks.
    Jason Dulberg
    Extreme MTB
    http://extreme.nas.net

  2. #2
    ********* wombat firepages's Avatar
    Join Date
    Jul 2000
    Location
    Perth Australia
    Posts
    1,717
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just move the brace?

    $result = mysql_query("SELECT * FROM agents WHERE id='$aid';",$link);
    while ($a_row =mysql_fetch_array ($result))
    {
    $agentto=$a_row[agentemail];
    $agentsubject="Listings Information Requested";
    $agentmessage="$to was forwarded information on";


    if($agentto){mail($agentto, $agentsubject, $agentmessage, "From: ".$fromName." <".$fromAddress.">") or print "Could not send mail.<BR><HR><BR><P>";
    }}

  3. #3
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your code seems a little confusing because you are using a loop (while)
    when I'm guessing that you are only expecting the result set to be one record
    long (ie, there is only one link owner per link. So I don't think you need the
    while loop at all just
    PHP Code:
    $result*=*mysql_query("SELECT***FROM*agents*WHERE*id='$aid';",$link);
    $a_row*=mysql_fetch_array*($result))
    $agentto=$a_row["agentemail"];
    $agentsubject="Listings*Information*Requested";
    $agentmessage="$to*was*forwarded*information*on";
    mail($agentto,*$agentsubject,*$agentmessage,*
            
    "From:*".$fromName."*<".$fromAddress.">")*
                    or*print*
    "Could*not*send*mail.<BR><HR><BR><P>"
    But anyway, I suspect that this is the problem. You have,

    $agentto=$a_row[agentemail];

    should be

    $agentto=$a_row["agentemail"];

  4. #4
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually Sid you do not need quotes around the array key unless there is a space in it. In this case since it is the name of a db column we know there won't be any spaces in it.

    PHP Code:
    while($row=mysql_fetch_array($result)) {
        print 
    $row[fieldname]."<br>";
        } 
    So this is perfectly valid.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  5. #5
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK then thanks for that freddy. I don't know, these crazy - anything goes - loosely typed languages! I was thinking from a C perspective where abc != "abc" and where abc would probably evaluate to some int value.

  6. #6
    SitePoint Addict
    Join Date
    Sep 2000
    Location
    Ontario, Canada
    Posts
    320
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I just tried to remove the while loop but I am still not getting the second message.

    So here's what I have now:

    PHP Code:
    $result mysql_query("SELECT * FROM agents WHERE id='$aid';",$link);
    $a_row=(mysql_fetch_array($result));
    $agentto=$a_row[agentemail];
    $agentsubject="Listings Information Requested";
    $agentmessage="$to was forwarded information on";
    mail($agentto$agentsubject$agentmessage"From: ".$fromName." <".$fromAddress.">") or print "Could not send mail.<BR><HR><BR><P>"
    The $to part of the code above should be populated with info from the form on the site.

    Any other ideas?

    Thanks for your help!
    Jason Dulberg
    Extreme MTB
    http://extreme.nas.net

  7. #7
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It seams that $agentto is not being assigned a value. That's my hunch.

    1) Stupid question - you do have a database connection established earlier in the script?

    2) You have a ";" at the end of your sql query string. When I do that with mysql_query() I get an error from my mysql server. But someone else here said that they have to put a ";" at the end of the query string or they get an error. Go figure!

    3) You need to add some temporary code to debug.
    PHP Code:
    $sql "SELECT***FROM*agents*WHERE*id='$aid';";
    echo 
    "<br> $sql <br>"// debug the sql string. Is $aid evaluating to the expected value?
    $result*=*mysql_query("SELECT***FROM*agents*WHERE*id='$aid';",$link);
    if (
    $result) { echo "Query executed OK <br>"; } // debug that the query executed ok
    echo "number rows " mysql_num_rows() . '<br>'// hopefully your result set has one row.
    $a_row=(mysql_fetch_array($result));
    $agentto=$a_row[agentemail];
    echo 
    $agentto// debug that you have a value assigned to $agentto;
    $agentsubject="Listings*Information*Requested";
    $agentmessage="$to*was*forwarded*information*on";
    mail($agentto,*$agentsubject,*$agentmessage,*"From:*".$fromName."*<".$fromAddress.">")*or*print*"Could*not*send*mail.<BR><HR><BR><P>"
    Now that might narrow down where the problem is.
    Last edited by freakysid; Apr 13, 2001 at 12:12.

  8. #8
    SitePoint Addict
    Join Date
    Sep 2000
    Location
    Ontario, Canada
    Posts
    320
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for your help on this one!

    Yep, I have a db connection. Some other data on the page is pulled from "agents" so its gotta be working.

    I just plugged in the code that you gave me and here's what it said when I ran it.

    SELECT * FROM agents WHERE id='';
    Query executed OK

    Warning: Wrong parameter count for mysql_num_rows() in /usr/local/etc/httpd/listings/friendmail.php on line 41
    number rows
    Could not send mail.

    - line 41 from your code is this:
    echo "number rows " . mysql_num_rows() . '<br>';

    Any ideas?

    thanks again for your time.
    Jason Dulberg
    Extreme MTB
    http://extreme.nas.net

  9. #9
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by jdulberg
    I just plugged in the code that you gave me and here's what it said when I ran it.

    SELECT * FROM agents WHERE id='';
    Query executed OK
    Ahah! Look at that SQL string. That's not a very useful query: WHERE id='' <- empty string
    So we can conclude that $aid is empty. Why doesn't this have the expected value? The problem lies somewhere earlier in your code you are not assigning $aid a value.


    Warning: Wrong parameter count for mysql_num_rows() in /usr/local/etc/httpd/listings/friendmail.php on line 41
    number rows
    Could not send mail.

    - line 41 from your code is this:
    echo "number rows " . mysql_num_rows() . '<br>';
    Silly me! should be:

    echo "number rows " . mysql_num_rows($result) . '<br>';

  10. #10
    SitePoint Addict
    Join Date
    Sep 2000
    Location
    Ontario, Canada
    Posts
    320
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yep, id wasn't populated. I found the problem -- it was in the <form action=> part.... I just needed to add aid=$id in there and it worked fine.

    Your code definitely helped!!

    Thanks again!
    Jason Dulberg
    Extreme MTB
    http://extreme.nas.net


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
  •