1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Help with PHP email event code

Discussion in 'PHP' started by NITRO23456, Feb 14, 2018.

  1. #1
    Hi all

    I am trying to send an email using a 'before record updated' event code.

    Currently I have this which works perfectly:

    
    $email="user@email.com";
    $from="donotreply@website.com";
    $msg="";
    $subject="New Record Added";
    
    $msg.= "Field One: ".$values["Field One"]."\r\n";
    $msg.= "Field Two: ".$values["Field Two"]."\r\n";
    
    $ret=runner_mail(array('to' => $email, 'subject' => $subject, 'body' => $msg, 'from'=>$from));
    if(!$ret["mailed"])
        echo $ret["message"];
    
    return true;
    
    Code (markup):
    What I would like to do is have $email dynamically filled rather than the hardcoded ''.

    'Field Two' is a field that contains the users full name that is the same that data that is held in the 'Full Name' field of the 'Users' table, e.g. Tom Jones. Also in the 'Users' table is another field called 'Email Address'.

    What do I need to add to the code above to get the script to pull the 'Email Address' from the 'Users' table based on the contents of 'Field Two' which is the same data as 'Full Name' in the 'Users' table?
     
    NITRO23456, Feb 14, 2018 IP
  2. phpmillion

    phpmillion Member

    Messages:
    145
    Likes Received:
    11
    Best Answers:
    4
    Trophy Points:
    45
    #2
    If you can describe your database structure at least, it would help. Since we don't even know what name of the field with user's email is in your database, it's impossible to provide you with any assistance. If you are looking for just a general answer, it would be:

    $email=$mysql_row['name_of_field_with_email_address'];
    PHP:
     
    phpmillion, Feb 14, 2018 IP
  3. NITRO23456

    NITRO23456 Well-Known Member

    Messages:
    516
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #3
    Thank you.

    'Users' is the name of the table and 'Email Address' is the name of the field that contains the email address. The field with the persons name is 'Full Name' in the 'Users' table and 'Field Two' in the record table above.

    I did add all this in my first post.
     
    NITRO23456, Feb 14, 2018 IP
  4. NITRO23456

    NITRO23456 Well-Known Member

    Messages:
    516
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #4
    So what I want is for it to lookup the users email address from the field 'Email Address' in the 'Users' table based on the data that is in 'Field Two' of the 'Records' table. Basically 'Full Name' in Users = 'Field Two' in Records
     
    NITRO23456, Feb 14, 2018 IP
  5. phpmillion

    phpmillion Member

    Messages:
    145
    Likes Received:
    11
    Best Answers:
    4
    Trophy Points:
    45
    #5
    Then this one should work for you:

    $email=$values['Email Address'];
    PHP:
     
    phpmillion, Feb 14, 2018 IP
  6. NITRO23456

    NITRO23456 Well-Known Member

    Messages:
    516
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #6
    Hi this doesn't work.

    Surely there needs to be some sort of lookup between the name of the person in 'Field Two' (remember this is the 'Records' table) and their associated email address contained in the 'Email Address' field of the 'Users' table.
     
    NITRO23456, Feb 14, 2018 IP
  7. phpmillion

    phpmillion Member

    Messages:
    145
    Likes Received:
    11
    Best Answers:
    4
    Trophy Points:
    45
    #7
    Sorry, I thought you "extracted" email address before running the mailer script.

    Please note you also need to "extract" email address (if it's in a different table) before running the mailer, just like you "extract" Records table.
     
    phpmillion, Feb 14, 2018 IP
  8. NITRO23456

    NITRO23456 Well-Known Member

    Messages:
    516
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #8
    Any help in how to do this would be appreciated. This is my question - I don't know what I need to add to my script above to achieve this?

    I have added this to the top of the script but it doesn't help:

     
    NITRO23456, Feb 14, 2018 IP
  9. creativeGenius

    creativeGenius Well-Known Member

    Messages:
    273
    Likes Received:
    5
    Best Answers:
    1
    Trophy Points:
    120
    #9
    try to check first if your query is getting any result or is pulling any record
     
    creativeGenius, Feb 14, 2018 IP
  10. phpmillion

    phpmillion Member

    Messages:
    145
    Likes Received:
    11
    Best Answers:
    4
    Trophy Points:
    45
    #10
    Now, try to run this exact query via phpmyadmin and you will see what is wrong with your query. Just be sure to replace ".$values["Field Two"]." with actual name you want to fetch.

    SELECT `Email Address` FROM Users WHERE `Full Name` = ".$values["Field Two"]."
    Code (markup):
    Also, your query is very insecure. I could modify or delete records in your database by simply entering some "special" text as my username. You should stop using this type of queries immediately, but I guess it's another story now...
     
    phpmillion, Feb 14, 2018 IP
  11. hdewantara

    hdewantara Well-Known Member

    Messages:
    536
    Likes Received:
    47
    Best Answers:
    25
    Trophy Points:
    155
    #11
    If that there's no possibility of your users to enter values other than given in Users' "Full Name" record (which is a false assumption) then try edit a line in your code on post #8 from:
    $email="user@email.com, $result";
    PHP:
    to just:
    $email = $result;
    PHP:
    What do you see?
     
    hdewantara, Feb 16, 2018 IP
  12. Blizzardofozz

    Blizzardofozz Well-Known Member

    Messages:
    132
    Likes Received:
    9
    Best Answers:
    1
    Trophy Points:
    118
    #12
    What software are you using? What is this CustomQuery function? Is some other step necessary? How do you get $values variable? What is the var_dump of $result?

    If you are using PHPRunner I see: $data= db_fetch_array($rs);
     
    Blizzardofozz, Feb 20, 2018 IP