B
B
boris tyrepharm2020-02-09 14:37:26
1C-Bitrix
boris tyrepharm, 2020-02-09 14:37:26

How to view an email before sending it to Bitrix?

Good afternoon!

I'm editing the mail template for the SALE_NEW_ORDER mail event and want to make sure the correct information is sent to the clients in the correct display.
I'm trying to debug the layout of the corresponding mail template in Bitrix, so I need to see how the letter will look, but at the same time, so that the letter is not sent to the user.

How or means is it possible to do this?

The table b_event, unfortunately, stores only the fields of the letter, and not the entire HTML representation.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey Nikolaev, 2020-02-10
@borisevstratov

boris tyrepharm , unfortunately you can't see "future" emails, as such generation is very complicated.
But you can view an existing email in the new design. Also - you can only see what your email will look like if it is displayed in a browser, but it's not the same as if it goes through the MTA and is displayed in Outlook/Thundebird/OWA etc.
For example, I want to see how approximately (*) the message with ID 336020 (in the b_event table) will look like after changing the design in an existing template.

use Bitrix\Main\Mail;

/**
 * Get from b_event table
 * @var integer Existed event id
 */
$displayedEventId = 336020;

/**
 * List of site ids, for event theme generation
 * must be replaced by current site id in public
 * @var array
 */
$arSites = [
  's1'
];

try
{
  /**
   * First, try to find event
   */
  $arEvent = Mail\Internal\EventTable::getRow([
    'filter' => [
      '=ID' => $displayedEventId,
    ]
  ]);

  if ( !$arEvent )
  {
    throw new \Exception('Event not found');
  }

  $arEvent['FIELDS'] = $arEvent['C_FIELDS'];

  /**
   * Try to find all message templates for 
   * sites. In event handler we send for one letter
   * per site.
   */
  $arEventMessageFilter = [
    '=ACTIVE' => 'Y',
    '=EVENT_NAME' => $arEvent["EVENT_NAME"],
    '=EVENT_MESSAGE_SITE.SITE_ID' => $arSites,
  ];

  $messageDb = Mail\Internal\EventMessageTable::getList([
    'select' => ['ID'],
    'filter' => $arEventMessageFilter,
    'group' => ['ID']
  ]);

  foreach ($messageDb as $arMessage)
  {
    $eventMessage = Mail\Internal\EventMessageTable::getRowById($arMessage['ID']);

    $eventMessage['FILES'] = array();
    $attachmentDb = Mail\Internal\EventMessageAttachmentTable::getList(array(
      'select' => array('FILE_ID'),
      'filter' => array('=EVENT_MESSAGE_ID' => $arMessage['ID']),
    ));
    while($arAttachmentDb = $attachmentDb->fetch())
    {
      $eventMessage['FILE'][] = $arAttachmentDb['FILE_ID'];
    }

    $arFields = $arEvent['FIELDS'];

    // get message object for send mail
    $arMessageParams = array(
      'EVENT' => $arEvent,
      'FIELDS' => $arFields,
      'MESSAGE' => $eventMessage,
      'SITE' => $arSites,
      'CHARSET' => $charset,
    );
    $message = Mail\EventMessageCompiler::createInstance($arMessageParams);
    $message->compile();
    echo $message->getMailBody();
  }
}
catch( \Exception $e )
{
  var_dump($e);
}

S
scarardss, 2020-02-09
@scaardss

Change the email address in the settings of the main module to your test one and send it to yourself, or you can view it in the visual editor of the mail template

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question