Email Notification Determined by State

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
Hickcox
Posts: 4
Joined: 2017-02-16 02:56

Email Notification Determined by State

Post by Hickcox » 2017-07-14 13:41

I have an AppGini-created registration form on a website. People (guests, not members) register from different states. I want to send an email to the coordinator of that when someone registers - the email would contain the data on the form. It doesn't currently work.

I've adapted the script created by shasta59 in 2013 ( https://forums.appgini.com/phpbb/viewtopic.php?f=7&t=58 ). He created a second table to record areas and their email address. When certain data is in the entry form, it triggers the correct email address to be brought in.

My version is below.

The database is DB_Registration

The table people enter their data into is Registration
- The field where they enter their state is State

The table where I list my regions and their email is Regions
- The field with the region name is Region
- The field with the email to send to is Email

Here is the code in the hooks file: (I've tried a basic send code, and that did send all entry data from each entry to a static email address.) But the code below makes absolutely nothing happen. What thing or things might I have wrong?



function Registration_after_insert($data, $memberInfo, &$args){

foreach($data as $field => $value){
$messageData .= "$field: $value \n";
}
if ($data['State'] == 'AL'){

$result = mysql_query("SELECT * FROM DB_Registration.Regions WHERE Region= 'Alabama'");
while($row = mysql_fetch_array($result))
mail($row['Email'] , 'Alabama' , 'You have a new registration from Alabama. ');

} elseif ($data['State'] == 'FL') {
$result = mysql_query("SELECT * FROM DB_Registration.Regions WHERE Region= 'Florida'");
while($row = mysql_fetch_array($result))
mail($row['Email'] , 'Florida' , 'You have a new registration from Florida. ');

} elseif ($data['State'] == 'GA') {
$result = mysql_query("SELECT * FROM DB_Registration.Regions WHERE Region= 'Georgia'");
while($row = mysql_fetch_array($result))
mail($row['Email'] , 'Georgia' , 'You have a new registration from Georgia. ');
}

foreach($data as $field => $value){
$messageData .= "$field: $value \n";
}
mail($memberInfo['Email'], 'Thank you for volunteering to glean with us. We'll get back to you soon.', $messageData, 'From: [email protected]');

return TRUE;
}


Thanks for any thoughts / ideas / wisdom.

- Mike

Post Reply