how to send notifications and emails
sending notifications and emails are very important features of a facebook app. now i’m going to show how you will send notifications and emails to users.
there are two types of notifications: user-to-user and application-to-user
- a user-to-user notification is sent on behalf of one user to one or more other users
- application-to-user notifications are sent on an application’s behalf and do not require an active session.
case 1: suppose you have an application question/answer type. let user ‘x’ sent a question to user ‘y’. so how will you notify user ‘y’ that he received a question. you can send a notification to user ‘y’ from user ‘x’ and also you could send an email to user ‘y’ from user ‘x’.
solution: for sending notification you could write this code
/*------- sends a notification or request to a set of users. notifications are items sent by an application to a user's notifications page in response to some sort of user activity within an application ----------*/
// $facebook->api_client->notifications_send(ids, notificationmessage, notificationtype);
$facebook->api_client->notifications_send('654321890', "you've received a msg from <fb:name uid='7464635353' />", 'user_to_user');
this notification is sent from user to user, that’s why you’ve to mention notification type as ‘user_to_user’
another imortant thing is that, you could send same notifications to more than one users as a single api call. just specify the ids as a comman separated list like
$facebook->api_client->notifications_send('654321890,656565654, 49393939', "msg", 'user_to_user');

case 2: let you also want to send an email to user ‘y’ from user ‘x’ in the situation of case 1.
solution: you could only send emails to the users, who have both authorized your application and granted it the email extended permission. so how will you ask the user for accepting extended permission for email. here is the way. write the below code in your view page or layout:
<fb:prompt-permission perms="email">Would you like to receive email from our application?</fb:prompt-permission>
this will render this link in your view page:

when user will click this link, a dialog box will open and show user a message to accept receive emails permission. if user accept this permission, then this link will not shown to that user in future.
here is the api call that you have to use to send email:
//$facebook->api_client->notifications_sendEmail('recipients', 'mail_subject', "tex", 'fbml');
$facebook->api_client->notifications_sendEmail('73737373', 'you received a question', "", "hi user <fb:name uid='47363633' /> has sent you a message");
remember the parameters:
- recipients: a comma-separated list of recipient IDs. you can email up to 100 people at a time.
- subject: the subject of the email message. as of 10/28/2008, the subject will accept a limited set of fbml tags, including names, and tags related to internationalization.
- text: the plain text version of the email content. you must include a non-empty value for at least one of either the fbml or text parameters. the fbml input takes precedence, but if the given fbml value is invalid or cannot be rendered, then the text will be used instead. there is currently no character limit on the length of either the text or fbml body.
- fbml: the fbml version of the email. you must include a non-empty value for at least one of either the fbml or text parameters. the fbml parameter is a stripped-down set of fbml that allows only html/fbml tags that result in text, links, linebreaks, as well as tags related to internationalization.
references:
- http://wiki.developers.facebook.com/index.php/Notifications.sendEmail
- http://wiki.developers.facebook.com/index.php/Notifications.send
- http://wiki.developers.facebook.com/index.php/Fb:prompt-permission





