本文整理汇总了PHP中CRM_Utils_Mail::send方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Utils_Mail::send方法的具体用法?PHP CRM_Utils_Mail::send怎么用?PHP CRM_Utils_Mail::send使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Utils_Mail
的用法示例。
在下文中一共展示了CRM_Utils_Mail::send方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testHookAlterMailer
public function testHookAlterMailer()
{
$test = $this;
$mockMailer = new CRM_Utils_FakeObject(array('send' => function ($recipients, $headers, $body) use($test) {
$test->calls['send']++;
$test->assertEquals(array('to@example.org'), $recipients);
$test->assertEquals('Subject Example', $headers['Subject']);
}));
CRM_Utils_Hook::singleton()->setHook('civicrm_alterMailer', function (&$mailer, $driver, $params) use($test, $mockMailer) {
$test->calls['civicrm_alterMailer']++;
$test->assertTrue(is_string($driver) && !empty($driver));
$test->assertTrue(is_array($params));
$test->assertTrue(is_callable(array($mailer, 'send')));
$mailer = $mockMailer;
});
$params = array();
$params['groupName'] = 'CRM_Core_Config_MailerTest';
$params['from'] = 'From Example <from@example.com>';
$params['toName'] = 'To Example';
$params['toEmail'] = 'to@example.org';
$params['subject'] = 'Subject Example';
$params['text'] = 'Example text';
$params['html'] = '<p>Example HTML</p>';
CRM_Utils_Mail::send($params);
$this->assertEquals(1, $this->calls['civicrm_alterMailer']);
$this->assertEquals(1, $this->calls['send']);
// once more, just to make sure the hooks are called right #times
CRM_Utils_Mail::send($params);
CRM_Utils_Mail::send($params);
$this->assertEquals(1, $this->calls['civicrm_alterMailer']);
$this->assertEquals(3, $this->calls['send']);
}
示例2: sendMailToParents
static function sendMailToParents($childID, $subjectTPL, $messageTPL, $templateVars, $additionalCC = null)
{
require_once 'SFS/Utils/Relationship.php';
$parentInfo = array();
SFS_Utils_Relationship::getParents($childID, $parentInfo, false);
// make sure we unset the older parents
for ($count = 1; $count < 5; $count++) {
$templateVars["parent_{$count}_Name"] = null;
}
$count = 1;
$toDisplayName = $toEmail = $cc = null;
foreach ($parentInfo as $parent) {
$templateVars["parent_{$count}_Name"] = $parent['name'];
if ($parent['email']) {
if (!$toEmail) {
$toDisplayName = $parent['name'];
$toEmail = $parent['email'];
} else {
if (!empty($cc)) {
$cc .= ", ";
}
$cc .= $parent['email'];
}
}
$count++;
}
if ($additionalCC) {
if (!empty($cc)) {
$cc .= ", ";
}
$cc .= $additionalCC;
}
// return if we dont have a toEmail
if (!$toEmail) {
return;
}
require_once 'SFS/Utils/Query.php';
list($templateVars['childName'], $templateVars['childEmail']) = SFS_Utils_Query::getNameAndEmail($childID);
$template = CRM_Core_Smarty::singleton();
$template->assign($templateVars);
require_once 'CRM/Utils/Mail.php';
require_once 'CRM/Utils/String.php';
$params = array('from' => self::SFS_FROM_EMAIL, 'toName' => $toDisplayName, 'toEmail' => $toEmail, 'subject' => $template->fetch($subjectTPL), 'text' => $template->fetch($messageTPL), 'cc' => $cc, 'bcc' => self::SFS_BCC_EMAIL);
CRM_Utils_Mail::send($params);
}
示例3: testSend
/**
* Basic send.
*/
public function testSend()
{
$contact_params_1 = array('first_name' => substr(sha1(rand()), 0, 7), 'last_name' => 'Anderson', 'email' => substr(sha1(rand()), 0, 7) . '@example.org', 'contact_type' => 'Individual');
$contact_id_1 = $this->individualCreate($contact_params_1);
$contact_params_2 = array('first_name' => substr(sha1(rand()), 0, 7), 'last_name' => 'Xylophone', 'email' => substr(sha1(rand()), 0, 7) . '@example.org', 'contact_type' => 'Individual');
$contact_id_2 = $this->individualCreate($contact_params_2);
$subject = 'Test spool';
$params = array('from' => CRM_Utils_Mail::formatRFC822Email($contact_params_1['first_name'] . " " . $contact_params_1['last_name'], $contact_params_1['email']), 'toName' => $contact_params_2['first_name'] . " " . $contact_params_2['last_name'], 'toEmail' => $contact_params_2['email'], 'subject' => $subject, 'text' => self::$bodytext, 'html' => "<p>\n" . self::$bodytext . '</p>');
CRM_Utils_Mail::send($params);
$mail = $this->_mut->getMostRecentEmail('raw');
$this->assertContains("Subject: {$subject}", $mail);
$this->assertContains(self::$bodytext, $mail);
$mail = $this->_mut->getMostRecentEmail('ezc');
$this->assertEquals($subject, $mail->subject);
$this->assertContains($contact_params_1['email'], $mail->from->email, 'From address incorrect.');
$this->assertContains($contact_params_2['email'], $mail->to[0]->email, 'Recipient incorrect.');
$context = new ezcMailPartWalkContext(array(get_class($this), 'mailWalkCallback'));
$mail->walkParts($context, $mail);
}
示例4: processSignature
/**
* Take the signature form and send an email to the recipient.
*
* @param CRM_Campaign_Form_Petition_Signature $form
* The petition form.
*/
public function processSignature($form)
{
// Get the message.
$messageField = $this->findMessageField();
if ($messageField === FALSE) {
return;
}
$message = empty($form->_submitValues[$messageField]) ? $this->petitionEmailVal[$this->fields['Default_Message']] : $form->_submitValues[$messageField];
// If message is left empty and no default message, don't send anything.
if (empty($message)) {
return;
}
// Setup email message:
$mailParams = array('groupName' => 'Activity Email Sender', 'from' => $this->getSenderLine($form->_contactId), 'toName' => $this->petitionEmailVal[$this->fields['Recipient_Name']], 'toEmail' => $this->petitionEmailVal[$this->fields['Recipient_Email']], 'subject' => $this->petitionEmailVal[$this->fields['Subject']], 'text' => $message);
if (!CRM_Utils_Mail::send($mailParams)) {
CRM_Core_Session::setStatus(ts('Error sending message to %1', array('domain' => 'com.aghstrategies.petitionemail', 1 => $mailParams['toName'])));
} else {
CRM_Core_Session::setStatus(ts('Message sent successfully to %1', array('domain' => 'com.aghstrategies.petitionemail', 1 => $mailParams['toName'])));
}
parent::processSignature($form);
}
示例5: civicrm_api3_speakcivi_sendconfirm
function civicrm_api3_speakcivi_sendconfirm($params)
{
$query = 'SELECT msg_subject subject, msg_text text, msg_html html, pdf_format_id format
FROM civicrm_msg_template mt
WHERE mt.id = %1 AND mt.is_default = 1';
$sqlParams = array(1 => array($params['messageTemplateID'], 'String'));
$dao = CRM_Core_DAO::executeQuery($query, $sqlParams);
$dao->fetch();
if (!$dao->N) {
CRM_Core_Error::fatal(ts('No such message template: id=%1.', array(1 => $params['messageTemplateID'])));
}
$confirmation_block_html = '';
$confirmation_block_text = '';
$language = $params['language'];
if ($params['confirmation_block']) {
$cgid = $params['contact_id'];
$aid = $params['activity_id'];
$campaign_id = $params['campaign_id'];
$hash = sha1(CIVICRM_SITE_KEY . $cgid);
$url_confirm_and_keep = CRM_Utils_System::url('civicrm/speakcivi/confirm', "id={$cgid}&aid={$aid}&cid={$campaign_id}&hash={$hash}&utm_source=civicrm&utm_medium=email&utm_campaign=speakout_confirm", true);
$url_confirm_and_not_receive = CRM_Utils_System::url('civicrm/speakcivi/optout', "id={$cgid}&aid={$aid}&cid={$campaign_id}&hash={$hash}&utm_source=civicrm&utm_medium=email&utm_campaign=speakout_optout", true);
$template = CRM_Core_Smarty::singleton();
$template->assign('url_confirm_and_keep', $url_confirm_and_keep);
$template->assign('url_confirm_and_not_receive', $url_confirm_and_not_receive);
$confirmation_block_html = $template->fetch('../templates/CRM/Speakcivi/Page/ConfirmationBlock.' . $language . '.html.tpl');
$confirmation_block_text = $template->fetch('../templates/CRM/Speakcivi/Page/ConfirmationBlock.' . $language . '.text.tpl');
$params['subject'] = getSubjectConfirm($language);
} else {
$params['subject'] = getSubjectImpact($language);
}
$params['html'] = str_replace("#CONFIRMATION_BLOCK", $confirmation_block_html, $dao->html);
$params['text'] = str_replace("#CONFIRMATION_BLOCK", $confirmation_block_text, $dao->text);
$params['format'] = $dao->format;
$dao->free();
$sent = CRM_Utils_Mail::send($params);
return civicrm_api3_create_success($sent, $params);
}
示例6: sendTemplate
/**
* Send an email from the specified template based on an array of params.
*
* @param array $params
* A string-keyed array of function params, see function body for details.
*
* @return array
* Array of four parameters: a boolean whether the email was sent, and the subject, text and HTML templates
*/
public static function sendTemplate($params)
{
$defaults = array('groupName' => NULL, 'valueName' => NULL, 'messageTemplateID' => NULL, 'contactId' => NULL, 'tplParams' => array(), 'from' => NULL, 'toName' => NULL, 'toEmail' => NULL, 'cc' => NULL, 'bcc' => NULL, 'replyTo' => NULL, 'attachments' => NULL, 'isTest' => FALSE, 'PDFFilename' => NULL);
$params = array_merge($defaults, $params);
CRM_Utils_Hook::alterMailParams($params, 'messageTemplate');
if ((!$params['groupName'] || !$params['valueName']) && !$params['messageTemplateID']) {
CRM_Core_Error::fatal(ts("Message template's option group and/or option value or ID missing."));
}
if ($params['messageTemplateID']) {
// fetch the three elements from the db based on id
$query = 'SELECT msg_subject subject, msg_text text, msg_html html, pdf_format_id format
FROM civicrm_msg_template mt
WHERE mt.id = %1 AND mt.is_default = 1';
$sqlParams = array(1 => array($params['messageTemplateID'], 'String'));
} else {
// fetch the three elements from the db based on option_group and option_value names
$query = 'SELECT msg_subject subject, msg_text text, msg_html html, pdf_format_id format
FROM civicrm_msg_template mt
JOIN civicrm_option_value ov ON workflow_id = ov.id
JOIN civicrm_option_group og ON ov.option_group_id = og.id
WHERE og.name = %1 AND ov.name = %2 AND mt.is_default = 1';
$sqlParams = array(1 => array($params['groupName'], 'String'), 2 => array($params['valueName'], 'String'));
}
$dao = CRM_Core_DAO::executeQuery($query, $sqlParams);
$dao->fetch();
if (!$dao->N) {
if ($params['messageTemplateID']) {
CRM_Core_Error::fatal(ts('No such message template: id=%1.', array(1 => $params['messageTemplateID'])));
} else {
CRM_Core_Error::fatal(ts('No such message template: option group %1, option value %2.', array(1 => $params['groupName'], 2 => $params['valueName'])));
}
}
$mailContent = array('subject' => $dao->subject, 'text' => $dao->text, 'html' => $dao->html, 'format' => $dao->format);
$dao->free();
CRM_Utils_Hook::alterMailContent($mailContent);
// add the test banner (if requested)
if ($params['isTest']) {
$query = "SELECT msg_subject subject, msg_text text, msg_html html\n FROM civicrm_msg_template mt\n JOIN civicrm_option_value ov ON workflow_id = ov.id\n JOIN civicrm_option_group og ON ov.option_group_id = og.id\n WHERE og.name = 'msg_tpl_workflow_meta' AND ov.name = 'test_preview' AND mt.is_default = 1";
$testDao = CRM_Core_DAO::executeQuery($query);
$testDao->fetch();
$mailContent['subject'] = $testDao->subject . $mailContent['subject'];
$mailContent['text'] = $testDao->text . $mailContent['text'];
$mailContent['html'] = preg_replace('/<body(.*)$/im', "<body\\1\n{$testDao->html}", $mailContent['html']);
$testDao->free();
}
// replace tokens in the three elements (in subject as if it was the text body)
$domain = CRM_Core_BAO_Domain::getDomain();
$hookTokens = array();
$mailing = new CRM_Mailing_BAO_Mailing();
$mailing->subject = $mailContent['subject'];
$mailing->body_text = $mailContent['text'];
$mailing->body_html = $mailContent['html'];
$tokens = $mailing->getTokens();
CRM_Utils_Hook::tokens($hookTokens);
$categories = array_keys($hookTokens);
$contactID = CRM_Utils_Array::value('contactId', $params);
if ($contactID) {
$contactParams = array('contact_id' => $contactID);
$returnProperties = array();
if (isset($tokens['subject']['contact'])) {
foreach ($tokens['subject']['contact'] as $name) {
$returnProperties[$name] = 1;
}
}
if (isset($tokens['text']['contact'])) {
foreach ($tokens['text']['contact'] as $name) {
$returnProperties[$name] = 1;
}
}
if (isset($tokens['html']['contact'])) {
foreach ($tokens['html']['contact'] as $name) {
$returnProperties[$name] = 1;
}
}
// @todo CRM-17253 don't resolve contact details if there are no tokens
// effectively comment out this next (performance-expensive) line
// but unfortunately testing is a bit think on the ground to that needs to
// be added.
list($contact) = CRM_Utils_Token::getTokenDetails($contactParams, $returnProperties, FALSE, FALSE, NULL, CRM_Utils_Token::flattenTokens($tokens), 'CRM_Core_BAO_MessageTemplate');
$contact = $contact[$contactID];
}
$mailContent['subject'] = CRM_Utils_Token::replaceDomainTokens($mailContent['subject'], $domain, FALSE, $tokens['text'], TRUE);
$mailContent['text'] = CRM_Utils_Token::replaceDomainTokens($mailContent['text'], $domain, FALSE, $tokens['text'], TRUE);
$mailContent['html'] = CRM_Utils_Token::replaceDomainTokens($mailContent['html'], $domain, TRUE, $tokens['html'], TRUE);
if ($contactID) {
$mailContent['subject'] = CRM_Utils_Token::replaceContactTokens($mailContent['subject'], $contact, FALSE, $tokens['text'], FALSE, TRUE);
$mailContent['text'] = CRM_Utils_Token::replaceContactTokens($mailContent['text'], $contact, FALSE, $tokens['text'], FALSE, TRUE);
$mailContent['html'] = CRM_Utils_Token::replaceContactTokens($mailContent['html'], $contact, FALSE, $tokens['html'], FALSE, TRUE);
$contactArray = array($contactID => $contact);
CRM_Utils_Hook::tokenValues($contactArray, array($contactID), NULL, CRM_Utils_Token::flattenTokens($tokens), 'CRM_Core_BAO_MessageTemplate');
$contact = $contactArray[$contactID];
//.........这里部分代码省略.........
示例7: mailReport
static function mailReport($fileContent, $instanceID = null, $outputMode = 'html')
{
if (!$instanceID) {
return false;
}
$url = CRM_Utils_System::url("civicrm/report/instance/{$instanceID}", "reset=1", true);
$url = "Report Url: {$url} ";
$fileContent = $url . $fileContent;
require_once 'CRM/Core/BAO/Domain.php';
list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain::getNameAndEmail();
$params = array('id' => $instanceID);
$instanceInfo = array();
CRM_Core_DAO::commonRetrieve('CRM_Report_DAO_Instance', $params, $instanceInfo);
$from = '"' . $domainEmailName . '" <' . $domainEmailAddress . '>';
$toDisplayName = "";
//$domainEmailName;
$toEmail = CRM_Utils_Array::value('email_to', $instanceInfo);
$ccEmail = CRM_Utils_Array::value('email_cc', $instanceInfo);
$subject = CRM_Utils_Array::value('email_subject', $instanceInfo);
$attachments = CRM_Utils_Array::value('attachments', $instanceInfo);
require_once 'Mail/mime.php';
require_once "CRM/Utils/Mail.php";
return CRM_Utils_Mail::send($from, $toDisplayName, $toEmail, $subject, '', $ccEmail, null, null, $fileContent, $attachments);
}
示例8: sendInvoiceMail
function sendInvoiceMail($email, $displayName, $fromEmail, $fileName, $filePathName, $obj, $contactID, $contribution)
{
## getting contact detail
require_once 'api/v2/Contact.php';
$contactParams = array('id' => $contactID);
$contact =& civicrm_contact_get($contactParams);
## Check the contribution type to work out which email template we should be using
//print_r($contribution); exit;
$contributionTypeId = $contribution->contribution_type_id;
if ($contributionTypeId == '2') {
## Contribution Type - Membership
$emailTemplateName = 'Membership Invoice';
$params['bcc'] = 'test@example.com';
}
if ($contributionTypeId == '4') {
## Contribution Type - Events
$emailTemplateName = 'Participant Invoice';
$params['bcc'] = 'test@example.com';
}
## getting invoice mail template
$query = "SELECT * FROM civicrm_msg_template WHERE msg_title = '{$emailTemplateName}' AND is_active=1";
$dao = CRM_Core_DAO::executeQuery($query);
if (!$dao->fetch()) {
print "Not able to get Email Template";
exit;
}
$text = $dao->msg_text;
$html = $dao->msg_html;
$subject = $dao->msg_subject;
###################################################
require_once "CRM/Mailing/BAO/Mailing.php";
$mailing = new CRM_Mailing_BAO_Mailing();
$mailing->body_text = $text;
$mailing->body_html = $html;
$tokens = $mailing->getTokens();
require_once "CRM/Utils/Token.php";
$subject = CRM_Utils_Token::replaceDomainTokens($subject, $domain, true, $tokens['text']);
$text = CRM_Utils_Token::replaceDomainTokens($text, $domain, true, $tokens['text']);
$html = CRM_Utils_Token::replaceDomainTokens($html, $domain, true, $tokens['html']);
if ($contactID) {
$subject = CRM_Utils_Token::replaceContactTokens($subject, $contact, false, $tokens['text']);
$text = CRM_Utils_Token::replaceContactTokens($text, $contact, false, $tokens['text']);
$html = CRM_Utils_Token::replaceContactTokens($html, $contact, false, $tokens['html']);
}
// parse the three elements with Smarty
require_once 'CRM/Core/Smarty/resources/String.php';
civicrm_smarty_register_string_resource();
$smarty =& CRM_Core_Smarty::singleton();
foreach ($params['tplParams'] as $name => $value) {
$smarty->assign($name, $value);
}
###################################################
$params['text'] = $text;
$params['html'] = $html;
$params['subject'] = $subject;
// assigning from email
$params['from'] = $fromEmail;
#### live ###### uncomment it
$params['toName'] = $displayName;
$params['toEmail'] = $email;
#### test ###### comment it
#$params['toName'] = "Test";
#$params['toEmail'] = 'rajesh@millertech.co.uk';
# Left this in as hard coded for now as the default from email address doesn't seem to work
# We can probably do something with the contribution type for the from email addresses
$params['from'] = 'noreply@example.com';
$attach = array('fullPath' => $filePathName, 'mime_type' => 'pdf', 'cleanName' => $fileName);
## Commented out to test if attachments are causing the problem
$params['attachments'] = array($fileName => $attach);
require_once 'CRM/Utils/Mail.php';
// Comment to abort sending email
$sent = CRM_Utils_Mail::send($params);
if ($sent) {
echo "<br />Invoice sent <b>successfully</b> - {$email}</b><br /><br />";
## Insert a record into Log table - civicrm_mtl_invoice_log
$contribution_id = $contribution->id;
} else {
echo "<br />Invoice sent <b>faliure</b> - <b>{$email}</b>{$sent->message}<br /><br />";
}
//please comment this before setting up in LIVE
//exit;
}
示例9: sendTemplate
/**
* Send an email from the specified template based on an array of params
*
* @param array $params a string-keyed array of function params, see function body for details
*
* @return array of four parameters: a boolean whether the email was sent, and the subject, text and HTML templates
*/
static function sendTemplate($params)
{
$defaults = array('groupName' => null, 'valueName' => null, 'contactId' => null, 'tplParams' => array(), 'from' => null, 'toName' => null, 'toEmail' => null, 'cc' => null, 'bcc' => null, 'replyTo' => null, 'attachments' => null, 'isTest' => false);
$params = array_merge($defaults, $params);
if (!$params['groupName'] or !$params['valueName']) {
CRM_Core_Error::fatal(ts("Message template's option group and/or option value missing."));
}
// fetch the three elements from the db based on option_group and option_value names
$query = 'SELECT msg_subject subject, msg_text text, msg_html html
FROM civicrm_msg_template mt
JOIN civicrm_option_value ov ON workflow_id = ov.id
JOIN civicrm_option_group og ON ov.option_group_id = og.id
WHERE og.name = %1 AND ov.name = %2 AND mt.is_default = 1';
$sqlParams = array(1 => array($params['groupName'], 'String'), 2 => array($params['valueName'], 'String'));
$dao = CRM_Core_DAO::executeQuery($query, $sqlParams);
$dao->fetch();
if (!$dao->N) {
CRM_Core_Error::fatal(ts('No such message template: option group %1, option value %2.', array(1 => $params['groupName'], 2 => $params['valueName'])));
}
$subject = $dao->subject;
$text = $dao->text;
$html = $dao->html;
// add the test banner (if requested)
if ($params['isTest']) {
$query = "SELECT msg_subject subject, msg_text text, msg_html html\n FROM civicrm_msg_template mt\n JOIN civicrm_option_value ov ON workflow_id = ov.id\n JOIN civicrm_option_group og ON ov.option_group_id = og.id\n WHERE og.name = 'msg_tpl_workflow_meta' AND ov.name = 'test_preview' AND mt.is_default = 1";
$testDao = CRM_Core_DAO::executeQuery($query);
$testDao->fetch();
$subject = $testDao->subject . $subject;
$text = $testDao->text . $text;
$html = preg_replace('/<body(.*)$/im', "<body\\1\n{$testDao->html}", $html);
}
// replace tokens in the three elements
require_once 'CRM/Utils/Token.php';
require_once 'CRM/Core/BAO/Domain.php';
require_once 'api/v2/Contact.php';
require_once 'CRM/Mailing/BAO/Mailing.php';
$domain = CRM_Core_BAO_Domain::getDomain();
if ($params['contactId']) {
$contactParams = array('contact_id' => $params['contactId']);
$contact =& civicrm_contact_get($contactParams);
}
// replace tokens in subject as if it was the text body
foreach (array('subject' => 'text', 'text' => 'text', 'html' => 'html') as $type => $tokenType) {
if (!${$type}) {
continue;
}
// skip all of the below if the given part is missing
$bodyType = "body_{$tokenType}";
$mailing = new CRM_Mailing_BAO_Mailing();
$mailing->{$bodyType} = ${$type};
$tokens = $mailing->getTokens();
${$type} = CRM_Utils_Token::replaceDomainTokens(${$type}, $domain, true, $tokens[$tokenType]);
if ($params['contactId']) {
${$type} = CRM_Utils_Token::replaceContactTokens(${$type}, $contact, false, $tokens[$tokenType]);
}
}
// strip whitespace from ends and turn into a single line
$subject = "{strip}{$subject}{/strip}";
// parse the three elements with Smarty
require_once 'CRM/Core/Smarty/resources/String.php';
civicrm_smarty_register_string_resource();
$smarty =& CRM_Core_Smarty::singleton();
foreach ($params['tplParams'] as $name => $value) {
$smarty->assign($name, $value);
}
foreach (array('subject', 'text', 'html') as $elem) {
${$elem} = $smarty->fetch("string:{${$elem}}");
}
// send the template, honouring the target user’s preferences (if any)
$sent = false;
if ($params['toEmail']) {
$contactParams = array('email' => $params['toEmail']);
$contact =& civicrm_contact_get($contactParams);
$prefs = array_pop($contact);
if (isset($prefs['preferred_mail_format']) and $prefs['preferred_mail_format'] == 'HTML') {
$text = null;
}
if (isset($prefs['preferred_mail_format']) and $prefs['preferred_mail_format'] == 'Text') {
$html = null;
}
require_once 'CRM/Utils/Mail.php';
$sent = CRM_Utils_Mail::send($params['from'], $params['toName'], $params['toEmail'], $subject, $text, $params['cc'], $params['bcc'], $params['replyTo'], $html, $params['attachments']);
}
return array($sent, $subject, $text, $html);
}
示例10: sendMessage
/**
* Send the message to a specific contact.
*
* @param string $from
* The name and email of the sender.
* @param int $fromID
* @param int $toID
* The contact id of the recipient.
* @param string $subject
* The subject of the message.
* @param $text_message
* @param $html_message
* @param string $emailAddress
* Use this 'to' email address instead of the default Primary address.
* @param int $activityID
* The activity ID that tracks the message.
* @param null $attachments
* @param null $cc
* @param null $bcc
*
* @return bool
* TRUE if successful else FALSE.
*/
public static function sendMessage($from, $fromID, $toID, &$subject, &$text_message, &$html_message, $emailAddress, $activityID, $attachments = NULL, $cc = NULL, $bcc = NULL)
{
list($toDisplayName, $toEmail, $toDoNotEmail) = CRM_Contact_BAO_Contact::getContactDetails($toID);
if ($emailAddress) {
$toEmail = trim($emailAddress);
}
// make sure both email addresses are valid
// and that the recipient wants to receive email
if (empty($toEmail) or $toDoNotEmail) {
return FALSE;
}
if (!trim($toDisplayName)) {
$toDisplayName = $toEmail;
}
$activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
$targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
// create the params array
$mailParams = array('groupName' => 'Activity Email Sender', 'from' => $from, 'toName' => $toDisplayName, 'toEmail' => $toEmail, 'subject' => $subject, 'cc' => $cc, 'bcc' => $bcc, 'text' => $text_message, 'html' => $html_message, 'attachments' => $attachments);
if (!CRM_Utils_Mail::send($mailParams)) {
return FALSE;
}
// add activity target record for every mail that is send
$activityTargetParams = array('activity_id' => $activityID, 'contact_id' => $toID, 'record_type_id' => $targetID);
CRM_Activity_BAO_ActivityContact::create($activityTargetParams);
return TRUE;
}
示例11: sendTemplate
/**
* Send an email from the specified template based on an array of params
*
* @param array $params a string-keyed array of function params, see function body for details
*
* @return array of four parameters: a boolean whether the email was sent, and the subject, text and HTML templates
*/
static function sendTemplate($params)
{
$defaults = array('groupName' => NULL, 'valueName' => NULL, 'messageTemplateID' => NULL, 'contactId' => NULL, 'tplParams' => array(), 'from' => NULL, 'toName' => NULL, 'toEmail' => NULL, 'cc' => NULL, 'bcc' => NULL, 'replyTo' => NULL, 'attachments' => NULL, 'isTest' => FALSE, 'PDFFilename' => NULL);
$params = array_merge($defaults, $params);
if ((!$params['groupName'] || !$params['valueName']) && !$params['messageTemplateID']) {
CRM_Core_Error::fatal(ts("Message template's option group and/or option value or ID missing."));
}
if ($params['messageTemplateID']) {
// fetch the three elements from the db based on id
$query = 'SELECT msg_subject subject, msg_text text, msg_html html, pdf_format_id format
FROM civicrm_msg_template mt
WHERE mt.id = %1 AND mt.is_default = 1';
$sqlParams = array(1 => array($params['messageTemplateID'], 'String'));
} else {
// fetch the three elements from the db based on option_group and option_value names
$query = 'SELECT msg_subject subject, msg_text text, msg_html html, pdf_format_id format
FROM civicrm_msg_template mt
JOIN civicrm_option_value ov ON workflow_id = ov.id
JOIN civicrm_option_group og ON ov.option_group_id = og.id
WHERE og.name = %1 AND ov.name = %2 AND mt.is_default = 1';
$sqlParams = array(1 => array($params['groupName'], 'String'), 2 => array($params['valueName'], 'String'));
}
$dao = CRM_Core_DAO::executeQuery($query, $sqlParams);
$dao->fetch();
if (!$dao->N) {
if ($params['messageTemplateID']) {
CRM_Core_Error::fatal(ts('No such message template: id=%1.', array(1 => $params['messageTemplateID'])));
} else {
CRM_Core_Error::fatal(ts('No such message template: option group %1, option value %2.', array(1 => $params['groupName'], 2 => $params['valueName'])));
}
}
$subject = $dao->subject;
$text = $dao->text;
$html = $dao->html;
$format = $dao->format;
$dao->free();
// add the test banner (if requested)
if ($params['isTest']) {
$query = "SELECT msg_subject subject, msg_text text, msg_html html\n FROM civicrm_msg_template mt\n JOIN civicrm_option_value ov ON workflow_id = ov.id\n JOIN civicrm_option_group og ON ov.option_group_id = og.id\n WHERE og.name = 'msg_tpl_workflow_meta' AND ov.name = 'test_preview' AND mt.is_default = 1";
$testDao = CRM_Core_DAO::executeQuery($query);
$testDao->fetch();
$subject = $testDao->subject . $subject;
$text = $testDao->text . $text;
$html = preg_replace('/<body(.*)$/im', "<body\\1\n{$testDao->html}", $html);
$testDao->free();
}
// replace tokens in the three elements (in subject as if it was the text body)
$domain = CRM_Core_BAO_Domain::getDomain();
$hookTokens = array();
$mailing = new CRM_Mailing_BAO_Mailing();
$mailing->body_text = $text;
$mailing->body_html = $html;
$tokens = $mailing->getTokens();
CRM_Utils_Hook::tokens($hookTokens);
$categories = array_keys($hookTokens);
$contactID = CRM_Utils_Array::value('contactId', $params);
if ($contactID) {
$contactParams = array('contact_id' => $contactID);
$returnProperties = array();
if (isset($tokens['text']['contact'])) {
foreach ($tokens['text']['contact'] as $name) {
$returnProperties[$name] = 1;
}
}
if (isset($tokens['html']['contact'])) {
foreach ($tokens['html']['contact'] as $name) {
$returnProperties[$name] = 1;
}
}
list($contact) = CRM_Utils_Token::getTokenDetails($contactParams, $returnProperties, FALSE, FALSE, NULL, CRM_Utils_Token::flattenTokens($tokens), 'CRM_Core_BAO_MessageTemplate');
$contact = $contact[$contactID];
}
$subject = CRM_Utils_Token::replaceDomainTokens($subject, $domain, TRUE, $tokens['text'], TRUE);
$text = CRM_Utils_Token::replaceDomainTokens($text, $domain, TRUE, $tokens['text'], TRUE);
$html = CRM_Utils_Token::replaceDomainTokens($html, $domain, TRUE, $tokens['html'], TRUE);
if ($contactID) {
$subject = CRM_Utils_Token::replaceContactTokens($subject, $contact, FALSE, $tokens['text'], FALSE, TRUE);
$text = CRM_Utils_Token::replaceContactTokens($text, $contact, FALSE, $tokens['text'], FALSE, TRUE);
$html = CRM_Utils_Token::replaceContactTokens($html, $contact, FALSE, $tokens['html'], FALSE, TRUE);
$contactArray = array($contactID => $contact);
CRM_Utils_Hook::tokenValues($contactArray, array($contactID), NULL, CRM_Utils_Token::flattenTokens($tokens), 'CRM_Core_BAO_MessageTemplate');
$contact = $contactArray[$contactID];
$subject = CRM_Utils_Token::replaceHookTokens($subject, $contact, $categories, TRUE);
$text = CRM_Utils_Token::replaceHookTokens($text, $contact, $categories, TRUE);
$html = CRM_Utils_Token::replaceHookTokens($html, $contact, $categories, TRUE);
}
// strip whitespace from ends and turn into a single line
$subject = "{strip}{$subject}{/strip}";
// parse the three elements with Smarty
$smarty = CRM_Core_Smarty::singleton();
foreach ($params['tplParams'] as $name => $value) {
$smarty->assign($name, $value);
}
//.........这里部分代码省略.........
示例12: civicrm_api3_speakcivi_sendconfirm
function civicrm_api3_speakcivi_sendconfirm($params)
{
$confirmationBlock = $params['confirmation_block'];
$contactId = $params['contact_id'];
$campaignId = $params['campaign_id'];
$activityId = $params['activity_id'];
$campaignObj = new CRM_Speakcivi_Logic_Campaign($campaignId);
$locale = $campaignObj->getLanguage();
$params['from'] = $campaignObj->getSenderMail();
$params['format'] = null;
if ($confirmationBlock) {
$params['subject'] = $campaignObj->getSubjectNew();
$message = $campaignObj->getMessageNew();
} else {
$params['subject'] = $campaignObj->getSubjectCurrent();
$message = $campaignObj->getMessageCurrent();
}
if (!$message) {
if ($confirmationBlock) {
$message = CRM_Speakcivi_Tools_Dictionary::getMessageNew($locale);
$campaignObj->setCustomFieldBySQL($campaignId, $campaignObj->fieldMessageNew, $message);
} else {
$message = CRM_Speakcivi_Tools_Dictionary::getMessageCurrent($locale);
$campaignObj->setCustomFieldBySQL($campaignId, $campaignObj->fieldMessageCurrent, $message);
}
}
$contact = array();
$params_contact = array('id' => $contactId, 'sequential' => 1);
$result = civicrm_api3('Contact', 'get', $params_contact);
if ($result['count'] == 1) {
$contact = $result['values'][0];
}
/* CONFIRMATION_BLOCK */
$hash = sha1(CIVICRM_SITE_KEY . $contactId);
$utm_content = 'version_' . $contactId % 2;
$utm_campaign = $campaignObj->getUtmCampaign();
$url_confirm_and_keep = CRM_Utils_System::url('civicrm/speakcivi/confirm', "id={$contactId}&aid={$activityId}&cid={$campaignId}&hash={$hash}&utm_source=civicrm&utm_medium=email&utm_campaign={$utm_campaign}&utm_content={$utm_content}", true);
$url_confirm_and_not_receive = CRM_Utils_System::url('civicrm/speakcivi/optout', "id={$contactId}&aid={$activityId}&cid={$campaignId}&hash={$hash}&utm_source=civicrm&utm_medium=email&utm_campaign={$utm_campaign}&utm_content={$utm_content}", true);
$template = CRM_Core_Smarty::singleton();
$template->assign('url_confirm_and_keep', $url_confirm_and_keep);
$template->assign('url_confirm_and_not_receive', $url_confirm_and_not_receive);
$locales = getLocale($locale);
$confirmation_block_html = $template->fetch('../templates/CRM/Speakcivi/Page/ConfirmationBlock.' . $locales['html'] . '.html.tpl');
$confirmation_block_text = $template->fetch('../templates/CRM/Speakcivi/Page/ConfirmationBlock.' . $locales['text'] . '.text.tpl');
/* SHARING_BLOCK */
$template->clearTemplateVars();
$template->assign('url_campaign', $campaignObj->getUrlCampaign());
$template->assign('url_campaign_fb', prepareCleanUrl($campaignObj->getUrlCampaign()));
$template->assign('utm_campaign', $campaignObj->getUtmCampaign());
$template->assign('share_facebook', CRM_Speakcivi_Tools_Dictionary::getShareFacebook($locale));
$template->assign('share_twitter', CRM_Speakcivi_Tools_Dictionary::getShareTwitter($locale));
$template->assign('twitter_share_text', urlencode($campaignObj->getTwitterShareText()));
$sharing_block_html = $template->fetch('../templates/CRM/Speakcivi/Page/SharingBlock.html.tpl');
$template->clearTemplateVars();
$template->assign('contact', $contact);
$message = $template->fetch('string:' . $message);
$message_html = str_replace("#CONFIRMATION_BLOCK", html_entity_decode($confirmation_block_html), $message);
$message_text = str_replace("#CONFIRMATION_BLOCK", html_entity_decode($confirmation_block_text), $message);
$message_html = str_replace("#SHARING_BLOCK", html_entity_decode($sharing_block_html), $message_html);
$message_text = str_replace("#SHARING_BLOCK", html_entity_decode($sharing_block_html), $message_text);
$params['html'] = $message_html;
$params['text'] = convertHtmlToText($message_text);
$sent = CRM_Utils_Mail::send($params);
return civicrm_api3_create_success($sent, $params);
}
示例13: generatePDF
function generatePDF($send = FALSE, $template_id)
{
require_once 'CRM/Utils/PDF/Utils.php';
$fileName = $this->mandate->reference . ".pdf";
if ($send) {
$config = CRM_Core_Config::singleton();
$pdfFullFilename = $config->templateCompileDir . CRM_Utils_File::makeFileName($fileName);
file_put_contents($pdfFullFilename, CRM_Utils_PDF_Utils::html2pdf($this->html, $fileName, true, null));
list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain::getNameAndEmail();
$params = array();
$params['groupName'] = 'SEPA Email Sender';
$params['from'] = '"' . $domainEmailName . '" <' . $domainEmailAddress . '>';
$params['toEmail'] = $this->contact->email;
$params['toName'] = $params['toEmail'];
if (empty($params['toEmail'])) {
CRM_Core_Session::setStatus(sprintf(ts("Error sending %s: Contact doesn't have an email."), $fileName));
return false;
}
$params['subject'] = "SEPA " . $fileName;
if (!CRM_Utils_Array::value('attachments', $instanceInfo)) {
$instanceInfo['attachments'] = array();
}
$params['attachments'][] = array('fullPath' => $pdfFullFilename, 'mime_type' => 'application/pdf', 'cleanName' => $fileName);
$mail = $this->getMessage($template_id);
$params['text'] = "this is the mandate, please return signed";
$params['html'] = $this->getTemplate()->fetch("string:" . $mail["msg_html"]);
CRM_Utils_Mail::send($params);
// CRM_Core_Session::setStatus(ts("Mail sent"));
} else {
CRM_Utils_PDF_Utils::html2pdf($this->html, $fileName, false, null);
}
}
示例14: civicrm_api3_job_rapportagenamailings_mail
/**
* Send a email to ?? with the mailing report of one mailing
*
* @param type $mailing_id
*/
function civicrm_api3_job_rapportagenamailings_mail($mailing_id)
{
global $base_root;
// create a new Cor Page
$page = new CRM_Core_Page();
$page->_mailing_id = $mailing_id;
// create a new template
$template = CRM_Core_Smarty::singleton();
// from CRM/Mailing/Page/Report.php
// check that the user has permission to access mailing id
CRM_Mailing_BAO_Mailing::checkPermission($mailing_id);
$report = CRM_Mailing_BAO_Mailing::report($mailing_id);
//get contents of mailing
CRM_Mailing_BAO_Mailing::getMailingContent($report, $page);
$subject = ts('Mailing Gereed: %1', array(1 => $report['mailing']['name']));
$template->assign('report', $report);
// inlcude $base_root
$template->assign('base_root', $base_root);
$template->assign('subject', $subject);
// from CRM/Core/page.php
// only print
$template->assign('tplFile', 'CRM/Rapportagenamailings/Page/RapportMailing.tpl');
$content = $template->fetch('CRM/common/print.tpl');
CRM_Utils_System::appendTPLFile('CRM/Rapportagenamailings/Page/RapportMailing.tpl', $content, $page->overrideExtraTemplateFileName());
//its time to call the hook.
CRM_Utils_Hook::alterContent($content, 'page', 'CRM/Rapportagenamailings/Page/RapportMailing.tpl', $page);
//echo $content;
// send mail
$params = array('from' => 'frontoffice@vnv.nl', 'toName' => 'Front Office VnV', 'toEmail' => 'frontoffice@vnv.nl', 'subject' => $subject, 'text' => $subject, 'html' => $content, 'replyTo' => 'frontoffice@vnv.nl');
CRM_Utils_Mail::send($params);
}
示例15: processMandrillCalls
//.........这里部分代码省略.........
continue;
}
$value['mailing_id'] = $mail->id;
// IF no activity id in header then create new activity
if (empty($header[0])) {
self::createActivity($value, NULL, $header);
}
if (empty($header[2])) {
$params = array('job_id' => CRM_Core_DAO::getFieldValue($jobCLassName, $mail->id, 'id', 'mailing_id'), 'contact_id' => $emails['email']['contact_id'], 'email_id' => $emails['email']['id']);
$eventQueue = CRM_Mailing_Event_BAO_Queue::create($params);
$eventQueueID = $eventQueue->id;
$hash = $eventQueue->hash;
$jobId = $params['job_id'];
} else {
$eventQueueID = $header[3];
$hash = explode('@', $header[4]);
$hash = $hash[0];
$jobId = $header[2];
}
if ($eventQueueID) {
$mandrillActivtyParams = array('mailing_queue_id' => $eventQueueID, 'activity_id' => $header[0]);
CRM_Mte_BAO_MandrillActivity::create($mandrillActivtyParams);
}
$msgBody = '';
if (!empty($header[0])) {
$msgBody = CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $header[0], 'details');
}
$value['mail_body'] = $msgBody;
$bType = ucfirst(preg_replace('/_\\w+/', '', $value['event']));
$assignedContacts = array();
switch ($value['event']) {
case 'open':
$oe = new CRM_Mailing_Event_BAO_Opened();
$oe->event_queue_id = $eventQueueID;
$oe->time_stamp = date('YmdHis', $value['ts']);
$oe->save();
break;
case 'click':
if (CRM_Utils_Array::value(1, $header) == 'b') {
break;
}
$tracker = new CRM_Mailing_BAO_TrackableURL();
$tracker->url = $value['url'];
$tracker->mailing_id = $mail->id;
if (!$tracker->find(TRUE)) {
$tracker->save();
}
$open = new CRM_Mailing_Event_BAO_TrackableURLOpen();
$open->event_queue_id = $eventQueueID;
$open->trackable_url_id = $tracker->id;
$open->time_stamp = date('YmdHis', $value['ts']);
$open->save();
break;
case 'hard_bounce':
case 'soft_bounce':
case 'spam':
case 'reject':
if (empty($bounceType)) {
CRM_Core_PseudoConstant::populate($bounceType, 'CRM_Mailing_DAO_BounceType', TRUE, 'id', NULL, NULL, NULL, 'name');
}
//Delete queue in delivered since this email is not successfull
$delivered = new CRM_Mailing_Event_BAO_Delivered();
$delivered->event_queue_id = $eventQueueID;
if ($delivered->find(TRUE)) {
$delivered->delete();
}
$bounceParams = array('time_stamp' => date('YmdHis', $value['ts']), 'event_queue_id' => $eventQueueID, 'bounce_type_id' => $bounceType["Mandrill {$bType}"], 'job_id' => $jobId, 'hash' => $hash);
$bounceParams['bounce_reason'] = CRM_Utils_Array::value('bounce_description', $value['msg']);
if (empty($bounceParams['bounce_reason'])) {
$bounceParams['bounce_reason'] = CRM_Core_DAO::getFieldValue('CRM_Mailing_DAO_BounceType', $bounceType["Mandrill {$bType}"], 'description');
}
CRM_Mailing_Event_BAO_Bounce::create($bounceParams);
if (substr($value['event'], -7) == '_bounce') {
$mailingBackend = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'mandrill_smtp_settings');
if (CRM_Utils_Array::value('group_id', $mailingBackend)) {
list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain::getNameAndEmail();
$mailBody = ts('The following email failed to be delivered due to a') . " {$bType} Bounce :</br>\nTo: {$value['msg']['email']} </br>\nFrom: {$value['msg']['sender']} </br>\nSubject: {$value['msg']['subject']}</br>\nMessage Body: {$msgBody}";
$mailParams = array('groupName' => 'Mandrill bounce notification', 'from' => '"' . $domainEmailName . '" <' . $domainEmailAddress . '>', 'subject' => ts('Mandrill Bounce Notification'), 'text' => $mailBody, 'html' => $mailBody);
$query = "SELECT ce.email, cc.sort_name, cgc.contact_id FROM civicrm_contact cc\nINNER JOIN civicrm_group_contact cgc ON cgc.contact_id = cc.id\nINNER JOIN civicrm_email ce ON ce.contact_id = cc.id\nWHERE cc.is_deleted = 0 AND cc.is_deceased = 0 AND cgc.group_id = {$mailingBackend['group_id']} AND ce.is_primary = 1 AND ce.email <> %1";
$queryParam = array(1 => array($value['msg']['email'], 'String'));
$dao = CRM_Core_DAO::executeQuery($query, $queryParam);
while ($dao->fetch()) {
$mailParams['toName'] = $dao->sort_name;
$mailParams['toEmail'] = $dao->email;
CRM_Utils_Mail::send($mailParams);
$value['assignee_contact_id'][] = $dao->contact_id;
}
}
}
$bType = 'Bounce';
break;
}
// create activity for click and open event
if ($value['event'] == 'open' || $value['event'] == 'click' || $bType == 'Bounce') {
self::createActivity($value, $bType, $header);
}
}
}
}
}