Exemple #1
0
 /**
  * @param \Ip\Form $form
  * @param array $postData
  * @param array $data
  */
 public function sendEmail($form, $postData, $data)
 {
     $contentData = array();
     $websiteName = ipGetOptionLang('Config.websiteTitle');
     $websiteEmail = ipGetOptionLang('Config.websiteEmail');
     $from = $websiteEmail;
     $files = array();
     foreach ($form->getFields() as $field) {
         if ($field->getType() == \Ip\Form\Field::TYPE_REGULAR) {
             if (!isset($postData[$field->getName()])) {
                 $postData[$field->getName()] = null;
             }
             $title = $field->getLabel();
             $value = $field->getValueAsString($postData, $field->getName());
             $contentData[] = array('fieldClass' => get_class($field), 'title' => $title, 'value' => $value);
         }
         if (get_class($field) == 'Ip\\Form\\Field\\Email') {
             $userFrom = $field->getValueAsString($postData, $field->getName());
             if ($userFrom != '') {
                 $from = $userFrom;
             }
         }
         if (get_class($field) == 'Ip\\Form\\Field\\File') {
             $uploadedFiles = $field->getFiles($postData, $field->getName());
             $originalNames = $field->originalFileNames($postData, $field->getName());
             foreach ($uploadedFiles as $key => $uploadedFile) {
                 $files[] = array($uploadedFile, $originalNames[$key]);
             }
         }
     }
     $content = ipView('helperView/email_content.php', array('values' => $contentData))->render();
     $emailData = array('content' => $content);
     $email = ipEmailTemplate($emailData);
     //get page where this widget sits :)
     $fullWidgetRecord = \Ip\Internal\Content\Model::getWidgetRecord($postData['widgetId']);
     $pageTitle = '';
     if (isset($fullWidgetRecord['revisionId'])) {
         $revision = \Ip\Internal\Revision::getRevision($fullWidgetRecord['revisionId']);
         if (!empty($revision['pageId'])) {
             $pageTitle = ipPage($revision['pageId'])->getTitle();
         }
     }
     $subject = $websiteName . ': ' . $pageTitle;
     $emailQueue = new \Ip\Internal\Email\Module();
     if (!empty($data['sendTo']) && $data['sendTo'] == 'custom') {
         if (empty($data['emails'])) {
             $data['emails'] = '';
         }
         $emailList = preg_split("/[\\s,]+/", $data['emails']);
     } else {
         $emailList = array($websiteEmail);
     }
     foreach ($emailList as $listItem) {
         $emailQueue->addEmail($from, '', $listItem, '', $subject, $email, false, true, $files);
     }
     $emailQueue->send();
 }
Exemple #2
0
/**
 * Send e-mail message
 *
 * Adds new e-mail to the queue. If possible, ImpressPages will send the email immediately.
 * If hourly e-mail limit is exhausted, emails will be sent in the next hour.
 * ImpressPages always preserve 20% of hourly limit for urgent emails. So even if you have
 * just added thousands of non urgent e-mails, urgent e-mails will still be sent immediately.
 * Set $urgent parameter to false when delivery time is not so important, like newsletters, etc.
 * And set $urgent to true, when sending notification about purchase, etc.
 * @param string $from Sender's e-mail address
 * @param string $fromName Sender's name
 * @param string $to Recipient's email address
 * @param string $toName Recipient's name
 * @param string $subject Message subject
 * @param string $content Content to be sent (html or plain text. See $html attribute). If you need e-mail templates, use ipEmailTemplate() function to generate the content.
 * @param bool $urgent E-mail urgency
 * @param bool $html HTML mode. Set to false for plain text mode.
 * @param string|array|null $files Full pathname of the file to be attached or array of pathnames.
 */
function ipSendEmail($from, $fromName, $to, $toName, $subject, $content, $urgent = true, $html = true, $files = null)
{
    $emailQueue = new \Ip\Internal\Email\Module();
    $emailQueue->addEmail($from, $fromName, $to, $toName, $subject, $content, $urgent, $html, $files);
    $emailQueue->send();
}