Кодировать разрыв строки в HTML-письме, отправленном по правилам?
У меня есть правило, которое отправляет электронное письмо, когда узел редактируется определенным образом. Правило заполняет текст сообщения электронной почты значением поля <textarea>
из узла, который был обновлен.
Электронное письмо отправляется в формате HTML (не обычный текст), а <textarea>
имеет значение обычный текст (не отфильтрованный текст).
Когда электронное письмо доставляется, разрывы строк HTML (<br />
), которые я ввел в поле <textarea>
, не соблюдаются (они кодируются); это просто одна большая масса текста без разрывов строк.
Что мне нужно добавить в поле <textarea>
, чтобы в HTML-письме появились разрывы строк?
Я пробовал:
<br>
<br />
- \n
- \r
- \r\n
%0D%0A
<br />
- %3CBR+%2F%3E %3CBR+%2F%3E
Любой HTML, который я помещаю в поле, кодируется и не обрабатывается как HTML. Как мне вставить <br />
и сохранить его в виде HTML?
2 answers
Взгляните на мой ответ на " Как использовать правила для отправки электронного письма с телом, содержащим все элементы коллекции полей?". Он включает в себя правило (в формате экспорта), которое выглядит следующим образом:
{ "rules_field_collection_msg_and_email_body" : {
"LABEL" : "Field Collection msg and eMail body",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"REQUIRES" : [ "rules" ],
"ON" : { "node_view" : [] },
"IF" : [
{ "entity_has_field" : { "entity" : [ "node" ], "field" : "field_article_details" } },
{ "user_has_role" : {
"account" : [ "site:current-user" ],
"roles" : { "value" : { "3" : "3" } }
}
}
],
"DO" : [
{ "variable_add" : {
"USING" : {
"type" : "text",
"value" : "\u003Ch2\u003EThis is a demo of a node containing a field collection ... \u003C\/h2\u003E\r\n\u003Chr \/\u003E\r\n\u003Cstrong\u003EAbout this demo\u003C\/strong\u003E:\u003Cbr \/\u003E\r\n\u003Cbr \/\u003E\r\nThe machine name of the field collection is \u003Cstrong\u003Efield_article_details\u003C\/strong\u003E, and the number of values for it is unlimited.\u003Cbr \/\u003E\r\nThis field collection has these fields:\u003Cbr \/\u003E\u003Cbr \/\u003E\r\n- a text field labeled \u003Cstrong\u003EAuthor\u003C\/strong\u003E with machine name \u003Cstrong\u003Efield_author\u003C\/strong\u003E.\u003Cbr \/\u003E\r\n- a decimal field labeled \u003Cstrong\u003EPrice\u003C\/strong\u003E with machine name \u003Cstrong\u003Efield_price\u003C\/strong\u003E.\u003Cbr \/\u003E\r\n- a boolean field labeled \u003Cstrong\u003EApproval required\u003C\/strong\u003E with machine name \u003Cstrong\u003Efield_approval_required\u003C\/strong\u003E.\u003Cbr \/\u003E\u003Cbr \/\u003E\r\n\u003Chr \/\u003E\r\n\u003Cstrong\u003EPart 1\u003C\/strong\u003E: The list of items contained in the field collection with machine name \u003Cstrong\u003E\u0027field_article_details\u0027\u003C\/strong\u003E looks like so (note the comma to separate each item):\r\n\u003Chr \/\u003E\r\n[node:field_article_details]\r\n \u003Chr \/\u003E\r\n\u003Cstrong\u003EPart 2\u003C\/strong\u003E: The result of a \u003Cstrong\u003ERules loop\u003C\/strong\u003E that iterates for each of the field collection items (using its unique ID) ...\r\n\u003Chr \/\u003E"
},
"PROVIDE" : { "variable_added" : { "variable_for_email_body" : "Variable to use in eMail body" } }
}
},
{ "drupal_message" : { "message" : "\u003Ch2\u003EThis is a demo of a node containing a field collection ... \u003C\/h2\u003E\r\n\u003Chr \/\u003E\r\n\u003Cstrong\u003EAbout this demo\u003C\/strong\u003E:\u003Cbr \/\u003E\r\n\u003Cbr \/\u003E\r\nThe machine name of the field collection is \u003Cstrong\u003Efield_article_details\u003C\/strong\u003E, and the number of values for it is unlimited.\u003Cbr \/\u003E\r\nThis field collection has these fields:\u003Cbr \/\u003E\u003Cbr \/\u003E\r\n- a text field labeled \u003Cstrong\u003EAuthor\u003C\/strong\u003E with machine name \u003Cstrong\u003Efield_author\u003C\/strong\u003E.\u003Cbr \/\u003E\r\n- a decimal field labeled \u003Cstrong\u003EPrice\u003C\/strong\u003E with machine name \u003Cstrong\u003Efield_price\u003C\/strong\u003E.\u003Cbr \/\u003E\r\n- a boolean field labeled \u003Cstrong\u003EApproval required\u003C\/strong\u003E with machine name \u003Cstrong\u003Efield_approval_required\u003C\/strong\u003E.\u003Cbr \/\u003E\u003Cbr \/\u003E\r\n\u003Chr \/\u003E\r\n\u003Cstrong\u003EPart 1\u003C\/strong\u003E: The list of items contained in the field collection with machine name \u003Cstrong\u003E\u0027field_article_details\u0027\u003C\/strong\u003E looks like so (note the comma to separate each item):\r\n\u003Chr \/\u003E\r\n[node:field_article_details]\r\n \u003Chr \/\u003E\r\n\u003Cstrong\u003EPart 2\u003C\/strong\u003E: The result of a \u003Cstrong\u003ERules loop\u003C\/strong\u003E that iterates for each of the field collection items (using its unique ID) ...\r\n\u003Chr \/\u003E" } },
{ "LOOP" : {
"USING" : { "list" : [ "node:field-article-details" ] },
"ITEM" : { "article_details_item" : "article details item" },
"DO" : [
{ "data_set" : {
"data" : [ "variable-for-email-body" ],
"value" : "[variable-for-email-body:value]\u003Cbr \/\u003E\r\nThe host entity of this field collection item: [article-details-item:host]\u003Cbr \/\u003E\r\nThe unique ID of the field collection item: [article-details-item:item-id]\u003Cbr \/\u003E\r\nField \u0022field_author\u0022: [article-details-item:field-author]\u003Cbr \/\u003E\r\nField \u0022field_price\u0022: [article-details-item:field-price]\u003Cbr \/\u003E\r\nField \u0022field_approval_required\u0022: [article-details-item:field-approval-required]\u003Cbr \/\u003E\r\n\u003Chr \/\u003E"
}
},
{ "drupal_message" : { "message" : "The host entity of this field collection item: [article-details-item:host]\u003Cbr \/\u003E\r\nThe unique ID of the field collection item: [article-details-item:item-id]\u003Cbr \/\u003E\r\nField \u0022field_author\u0022: [article-details-item:field-author]\u003Cbr \/\u003E\r\nField \u0022field_price\u0022: [article-details-item:field-price]\u003Cbr \/\u003E\r\nField \u0022field_approval_required\u0022: [article-details-item:field-approval-required]\u003Cbr \/\u003E\r\n\u003Chr \/\u003E" } }
]
}
},
{ "mail" : {
"to" : [ "site:current-user:mail" ],
"subject" : "Demo of an eMail with a body containing all items of a field collection",
"message" : [ "variable-for-email-body" ],
"language" : [ "" ]
}
}
]
}
}
Несмотря на то, что ваш вопрос не является дубликатом этого вопроса, это правило включает решение, которое вы также можете применить в своем случае:
- Действие правил Добавьте переменную с именем машины
variable_for_email_body
. - Действие правил, чтобы на самом деле заполните содержимое этого
variable_for_email_body
(просто замените это содержимое в соответствии с вашими потребностями и включите любые HTML-теги, которые вы хотите использовать в теле нашей электронной почты). - Действие правил Отправка почты с телом сообщения, равным...
[variable-for-email-body]
.
Сделано ...
PS: очевидно, это для D7...
Вы можете попробовать код
/**
* Implements hook_mail().
*/
function mymodule_mail($key, &$message, $params) {
$headers = array(
'MIME-Version' => '1.0',
'Content-Type' => 'text/html; charset=UTF-8; format=flowed',
'Content-Transfer-Encoding' => '8Bit',
'X-Mailer' => 'Drupal'
);
foreach ($headers as $key => $value) {
$message['headers'][$key] = $value;
}
$message['subject'] = $params['subject'];
$message['body'] = $params['body'];
}