Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // http://www.gravityhelp.com/forums/topic/dynamic-population-notification-strategy
- // change the 28 here to your actual form ID
- add_filter('gform_notification_email_28', 'populate_admin_email_via_db', 10, 2);
- function populate_admin_email_via_db($email,$lead) {
- // set the email we're going to return equal to the email that was passed
- // in from the admin settings, in case something fails
- $selected_email = $email;
- // database connection details
- $dbname = 'databasename';
- $dbuser = 'databaseuser';
- $dbpass = 'databasepassword';
- $dbhost = 'localhost or database host';
- $dbtable = 'the table that holds your ID and email';
- // the hidden accountID value from the form. it was item 4 in the $lead array for my form
- $account = $lead[4];
- // establish the connection
- $link = mysql_connect($dbhost, $dbuser, $dbpass);
- // if connection was established
- if ($link){
- // change "user_email" here to the name of the field where your email is held
- // change "user_login" here to the name of the field that holds your accountID
- $sql = "SELECT user_email FROM $dbname.$dbtable WHERE user_login='$account' LIMIT 1;";
- $result = mysql_query($sql);
- // deal with the results
- if($result) {
- // the email address will be the one and only record returned
- $returned_record = mysql_fetch_row($result);
- if(!empty($returned_record))
- $selected_email = $returned_record[0];
- }
- // close the connection if it was established
- mysql_close($link);
- }
- // return an email address one way or the other
- return $selected_email;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement