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');

notifications_by_ma1

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:
email_extended_permiss_ma1

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:


Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • blinkbits
  • BlinkList
  • Blogosphere News
  • description
  • E-mail this story to a friend!
  • Furl
  • Gwar
  • LinkedIn
  • Ma.gnolia
  • MySpace
  • Ping.fm
  • Reddit
  • Slashdot
  • Spurl
  • StumbleUpon
  • TwitThis
  • Upnews

9 Responses to “how to send notifications and emails”

  1. viebone  on June 25th, 2009

    Great post! thanks and congratulations for your blog, is very useful.

    I have a doubt about your post, I understood how to send a user to user notification, did you explain how to send a app to user notification? how i do that? I have to make a admin pannel with a form to do that? wich do you think is the best way to do that?

    Thanks you very much.

  2. Vivek  on July 7th, 2009

    I have understand how to send notification but
    I am not able to understand what is view or layout page and how to seek permission for email .

  3. shilpa balaji  on August 21st, 2009

    iam not recieving any confirmation mail from your the facebook till now

  4. Chris  on September 10th, 2009

    How do I get permission to send a user-to-user notification? I understand that as soon as someone authorizes my app, I can send notifications to my app users FROM THE APP. That is not what I want.

    But what I’d like to do is as soon as someone adds my app, I’d like to send a notifcation FROM THAT PERSON to all of their friends that they took an action with my app and invite them to come do the same.

    does my question make sense?

  5. kishore  on October 8th, 2009

    Where do I need to put this piece of code:

    Would you like to receive email from our application?

    I am able to send notifications using notifications_send(..), but I am unable send mails using notifications_sendEmail(..)

    did you get my issue?

  6. Binit  on December 5th, 2009

    Its a “ready to use!” code.

  7. shoaibshaikh  on March 4th, 2010

    hey can you tell me the usage of proxied_email.. i tried to send email on proxied_email address but it never get into my email inbox???????

  8. abhay  on March 5th, 2010

    i am trying to send email using following code..
    $uids = array(1804592791,100000822006911);
    $csv = implode(”,”, $uids);
    $result=$facebook->api_client->notifications_sendEmail($csv,”Test: this should appear in the subject”, “This should appear in the body (plain text)”, “Test: this should appear in the body “);

    both above ids have given permissions using following code:
    $enable_email_perm=”Would you like to receive email from our application?”;
    echo $enable_email_perm;

    But both above ids are never receiving email…
    Has email apis deprecated ?
    what could be the alternative for sending email ?

  9. buzzknow  on June 23rd, 2010

    how to populate all user from application which granted for email permission?

    regards

Leave a Reply