CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Sending an email programmatically
Pages: [1]

Author Topic: Sending an email programmatically  (Read 3501 times)

TravelingPharaoh

  • I post occasionally
  • **
  • Posts: 39
  • Karma: 3
    • Traveling journey of a developer
  • CiviCRM version: 4.1.2
  • CMS version: Drupal 7
Sending an email programmatically
January 04, 2010, 10:01:11 pm
How can I send an email using CiviCRM functions? its a a simple email text, I wish it would send with an attachment but might be asking for too much.


Kurund Jalmi

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4169
  • Karma: 128
    • CiviCRM
  • CiviCRM version: 4.x, future
  • CMS version: Drupal 7, Joomla 3.x
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Sending an email programmatically
January 04, 2010, 10:22:19 pm
You can send it using hooks. For examples check civitest_civicrm_post() in http://svn.civicrm.org/civicrm/branches/v3.0/drupal/civitest.module.sample

HTh

Kurund
Found this reply helpful? Support CiviCRM

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Sending an email programmatically
January 05, 2010, 07:07:49 am

you can also use

CRM/Utils/Mail, function send( ). you can also send attachments via that function :)

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

TravelingPharaoh

  • I post occasionally
  • **
  • Posts: 39
  • Karma: 3
    • Traveling journey of a developer
  • CiviCRM version: 4.1.2
  • CMS version: Drupal 7
Re: Sending an email programmatically
January 12, 2010, 08:36:17 pm
thanks that did the trick.

To send attachements I had to do the following

Code: [Select]
                       $fromName  = 'Release Form Submitted';
$fromEmail = $from;
$from      = '"' . $fromName . '" <' . $fromEmail . '>';

$toEmail   = $event['cc_confirm'];
$toName    = $event['cc_confirm'];
$toName    = $toEmail;
$subject   = "Participant Release form:". $participant['display_name'];
$pct_completeness=calculate_profile_completeness($civiuserid);
$message   = "Dear Team Leader: Please review the participant information for ".
                                            $participant['display_name']." in the ".$event['event_title']." event. User has ".
                                            $pct_completeness." information completed on its profile.

This is an automatic email please don't respond ";
$attachment= array ();
$attachment['participant']=array('fullPath'=>'files/NTMParticipantRelease.pdf',
'mime_type'=>'application/pdf');
CRM_Utils_Mail::send( $from,
 $toName,
 $toEmail,
 $subject,
 $message,
 "info@northtexasmissions.org",//cc
 null, //bcc
 null, // reply-to
 false, //html
 $attachment
  );


I got the mime_type option from the list in the following link http://snipplr.com/view/1937/array-of-mime-types/ I also searched for "php mime types" in google to find other possible lists.
« Last Edit: January 12, 2010, 08:48:50 pm by TravelingPharaoh »

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Sending an email programmatically

This forum was archived on 2017-11-26.