small Question, I want that the BCC of the Mail sending is optional, but can’t find out how to manage.
$kirby->email([
'from' => "$mail_from",
'replyTo' => $mail_reply_to,
'to' => "$mail_to"
// I know this is completely wrong, but how to manage such a case?
if ( $page->mail_bcc()->isNotEmpty ) {
'bcc' => $page->mail_bcc(),
}
'subject' => "$mail_subject",
'body'=> "$mail_text"
]);
Very strange, I have tried with null but it hasn’t worked. But now, very fine! Now I can place the logic outside … I personally don’t like the if/else Shortcode
Another small Question, you wrote that I don’t need the quotes around my variables. This was also my thought. But without, it doesn’t work. Any idea why?
Yes, but the reason is that you pass a field object instead of a string, the better way to do that would be to explicitly store a string in your variable.
$mail_from = $page->mail_from()->html(); // or ->value() if you don't want to escape
Yes, it’s because $page variable is not known in the scope of your function. You either have to define it within your function or pass it as a parameter.
Hmmm, it’s very similar to my own try, but this doesn’t work … I thought I can save the time to enter everytime the $page to the function. Of course, yours is working
function url_replace($word, $page = $page) {
echo str_replace('{url}',$page->url(),$word);
}
$word = 'This example demos some string replacement {url}';
echo url_replace($word);