在YiiMailer中添加标题标记

在YiiMailer中添加标题标记

问题描述:

Problem

While Sending Mail via Postfix and through Amazon SES it throws me a ,

554 Message rejected: Email address is not verified.

Error message, And i have verified my From Email address and Amazon SES is in the production environment , so no issue there. This is what Amazon documentation says :

Email address is not verified—Your account is in the sandbox and one of the recipient email addresses has not been verified. This might apply to "Sender", "Return-Path", or "From" addresses.

If you have not requested production access to Amazon SES, you must verify every recipient email address except for the recipients provided by the Amazon SES mailbox simulator. You must also verify your own "From" address. For more information, see Verifying Email Addresses and Domains in Amazon SES and Testing Amazon SES Email Sending.

SO, After searching for solution i found out a BLOG POST explaining the fix for this issue, which says adding -f flag in email will solve this issue,

<?php
$to      = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: michael@chtoen.com' . "
" .
    'Return-Path: michael@chtoen.com' . "
" .
    'Reply-To: michael@chtoen.com' . "
";
mail($to, $subject, $message, $headers, '-f michael@chtoen.com');
?>

Which actually does solve the issue, But I cannot set it to the YiiMailer. For now i am adding this flag directly to php.ini as ,

sendmail_path to usr/sbin/sendmail -t -i -f "noreply@sbworkbench.com"

It works fine. But I don't want to do it this way.

What I have done

Is , Create the YiiMailer setup as ,

$mail = new YiiMailer('customerEmail', $data);
Common::setup_smtp($mail);
$mail->setLayout('mail');
$mail->render();
$mail->From = Yii::app()->params['adminEmail'];
$mail->FromName = 'PENDING NOTIFICATION';
$mail->Subject = $data['subject'];
$mail->AddAddress($data['sendTo']);

And for adding the flag I have tried ,

  1. Adding the flag itself in the From address : Results the same invalid email

    $mail->From= "-f exaple@example.com"

  2. Adding extra parameters "Form" with value as "-f exaple@example.com" : Results Duplicate Form Address (which is obvious :D)

Question :

  1. How can I set header flag using YiiMailer ?
  2. Is it related to misconfiguration of Postfix with Amazon SES ? However, The same setting is working fine for Java Application.

P.S

  1. The code works on sendmail and swiftmail without Amazon SES with no need of the header flag.

YiiMailer is a wrapper for PHPMailer. You can set the -f flag by setting the $Sender property of PHPMailer.

$mail->Sender = "michael@chtoen.com"