Setting emails in Yii1 to not trigger Out of Office responses.

  • You are here: Free PHP » Uncategorized » Setting emails in Yii1 to not trigger Out of Office responses.

Christian Weiske recently wrote on how to set emails in Laravel to not trigger Out of Office responses.

This is typically done for emails that are auto-generated – for processes such as “Forgot Password” functionality and the like. There’s an RFC for this. In essence, you add an “Auto-Submitted: auto-generated” header to the email.

As I’ve been adding “Forgot Password” functionality for a legacy project, I thought I would see how this would be done in Yii1:

$yMessage = new YiiMailMessage();

$yMessage->addTo($to);
$yMessage->setFrom($fromEmail, $fromName);

$yMessage->setBody($htmlMessage, "text/html", "UTF-8");

$yMessage->setSubject(Yii::t("Link for resetting your password"));

// Mark the email as auto-generated so "Out of office" responses aren't triggered. (RFC-3834)

// https://cweiske.de/tagebuch/laravel-notification-autosubmit.htm

$yMessage->getHeaders()->addTextHeader("Auto-Submitted", "auto-generated");

Yii::app()->mail->send($yMessage);

This is much simpler in Yii1 than Laravel as no callbacks are required.

Powered by Gewgley