Disclaimer: This does not check for an existing invitation. You should do that yourself according to your needs.

Using the entity api:

      
$email = 'someone@somewhere.com';

// legit email?
if ( ! valid_email_address( $email ) ) {
  return;
}

global $user;

// make a new invite
$invite = entity_create('invite', array('type' => 'invite_by_email') );
$invite->uid = $user->uid;

// get the default field values
$field_subject = field_info_instance( 'invite', 'field_invitation_email_subject', 'invite_by_email');
$field_body = field_info_instance( 'invite', 'field_invitation_email_body', 'invite_by_email');

$wrapper = entity_metadata_wrapper('invite', $invite);
$wrapper->field_invitation_email_address->set( $email );
$wrapper->field_invitation_email_subject->set( $field_subject['default_value'][0]['value'] );
$wrapper->field_invitation_email_body->set( $field_body['default_value'][0]['value'] );

// save & send
$wrapper->save();

About the Author

Jonathan Daggerhart

Long time Drupal and WordPress developer. I like to write modules and plugins, and I dabble in frontend and design.

Leave a Reply

Your email address will not be published. Required fields are marked *