Ejemplo n.º 1
0
 /**
  * @param       $action
  *
  * @return array
  */
 public static function sendEmail($tokens, $config, MauticFactory $factory, $lead)
 {
     $mailer = $factory->getMailer();
     $emails = !empty($config['to']) ? explode(',', $config['to']) : array();
     $fields = $lead->getFields();
     $email = $fields['core']['email']['value'];
     if (!empty($email)) {
         if ($config['copy_lead']) {
             $emails[] = $email;
         }
         $mailer->setReplyTo($email);
     }
     $mailer->setTo($emails);
     if (!empty($config['cc'])) {
         $emails = explode(',', $config['cc']);
         $mailer->setCc($emails);
     }
     if (!empty($config['bcc'])) {
         $emails = explode(',', $config['bcc']);
         $mailer->setBcc($emails);
     }
     $mailer->setSubject($config['subject']);
     $mailer->setTokens($tokens);
     $mailer->setBody($config['message']);
     $mailer->parsePlainText($config['message']);
     $mailer->send();
 }
Ejemplo n.º 2
0
 /**
  * @param               $tokens
  * @param               $config
  * @param MauticFactory $factory
  * @param Lead          $lead
  */
 public static function sendEmail($tokens, $config, MauticFactory $factory, Lead $lead)
 {
     $mailer = $factory->getMailer();
     $emails = !empty($config['to']) ? explode(',', $config['to']) : array();
     $mailer->setTo($emails);
     $leadEmail = $lead->getEmail();
     if (!empty($leadEmail)) {
         // Reply to lead for user convenience
         $mailer->setReplyTo($leadEmail);
     }
     if (!empty($config['cc'])) {
         $emails = explode(',', $config['cc']);
         $mailer->setCc($emails);
     }
     if (!empty($config['bcc'])) {
         $emails = explode(',', $config['bcc']);
         $mailer->setBcc($emails);
     }
     $mailer->setSubject($config['subject']);
     $mailer->setTokens($tokens);
     $mailer->setBody($config['message']);
     $mailer->parsePlainText($config['message']);
     $mailer->send();
     if ($config['copy_lead'] && !empty($leadEmail)) {
         // Send copy to lead
         $mailer->reset();
         $mailer->setTo($leadEmail);
         $mailer->setSubject($config['subject']);
         $mailer->setTokens($tokens);
         $mailer->setBody($config['message']);
         $mailer->parsePlainText($config['message']);
         $mailer->send();
     }
 }
Ejemplo n.º 3
0
 /**
  * @param               $tokens
  * @param               $config
  * @param MauticFactory $factory
  * @param Lead          $lead
  */
 public static function sendEmail($tokens, $config, MauticFactory $factory, Lead $lead)
 {
     // replace line brakes with <br> for textarea values
     if ($tokens) {
         foreach ($tokens as $token => &$value) {
             $value = nl2br(html_entity_decode($value));
         }
     }
     $leadEmail = $lead->getEmail();
     $mailer = $factory->getMailer();
     $emails = !empty($config['to']) ? array_fill_keys(explode(',', $config['to']), null) : [];
     if (!empty($emails)) {
         $mailer->setTo($emails);
         if (!empty($leadEmail)) {
             // Reply to lead for user convenience
             $mailer->setReplyTo($leadEmail);
         }
         if (!empty($config['cc'])) {
             $emails = array_fill_keys(explode(',', $config['cc']), null);
             $mailer->setCc($emails);
         }
         if (!empty($config['bcc'])) {
             $emails = array_fill_keys(explode(',', $config['bcc']), null);
             $mailer->setBcc($emails);
         }
         $mailer->setSubject($config['subject']);
         $mailer->addTokens($tokens);
         $mailer->setBody($config['message']);
         $mailer->parsePlainText($config['message']);
         $mailer->send(true);
     }
     if ($config['copy_lead'] && !empty($leadEmail)) {
         // Send copy to lead
         $mailer->reset();
         $mailer->setLead($lead->getProfileFields());
         $mailer->setTo($leadEmail);
         $mailer->setSubject($config['subject']);
         $mailer->addTokens($tokens);
         $mailer->setBody($config['message']);
         $mailer->parsePlainText($config['message']);
         $mailer->send(true);
     }
 }