Advertisement
chrishajer

pull email address from database based on query string

Aug 29th, 2011
426
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.85 KB | None | 0 0
  1. // http://www.gravityhelp.com/forums/topic/dynamic-population-notification-strategy
  2. // change the 28 here to your actual form ID
  3. add_filter('gform_notification_email_28', 'populate_admin_email_via_db', 10, 2);
  4. function populate_admin_email_via_db($email,$lead) {
  5.  
  6.         // set the email we're going to return equal to the email that was passed
  7.     // in from the admin settings, in case something fails
  8.         $selected_email = $email;
  9.  
  10.         // database connection details
  11.         $dbname  = 'databasename';
  12.         $dbuser  = 'databaseuser';
  13.         $dbpass  = 'databasepassword';
  14.         $dbhost  = 'localhost or database host';
  15.         $dbtable = 'the table that holds your ID and email';
  16.  
  17.         // the hidden accountID value from the form. it was item 4 in the $lead array for my form
  18.         $account = $lead[4];
  19.  
  20.         // establish the connection
  21.         $link = mysql_connect($dbhost, $dbuser, $dbpass);
  22.  
  23.         // if connection was established
  24.         if ($link){
  25.         // change "user_email" here to the name of the field where your email is held
  26.         // change "user_login" here to the name of the field that holds your accountID
  27.                 $sql = "SELECT user_email FROM $dbname.$dbtable WHERE user_login='$account' LIMIT 1;";
  28.                 $result = mysql_query($sql);
  29.  
  30.                 // deal with the results
  31.                 if($result) {
  32.                         // the email address will be the one and only record returned
  33.                         $returned_record = mysql_fetch_row($result);
  34.                         if(!empty($returned_record))
  35.                                 $selected_email = $returned_record[0];
  36.                 }
  37.                 // close the connection if it was established
  38.                 mysql_close($link);
  39.         }
  40.     // return an email address one way or the other
  41.         return $selected_email;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement