It took me quite sometime to fix this issue.
You can send emails with built-in CakePHP Email Component. But if you are sending email to any gmail address (like your-name@gmail.com), you can see an annoying 'mailed-by' header. It shows the name of your server, like mailed-by: dreamhost.com. It discloses your webhost. You may not like it. You may want to remove/hide this information. To do so, you need only one line of CakePHP code.
I have used following sendEmail() function in my /app/app_controller.php
file:// /app/app_controller.php
function sendEmail($subject, $view, $to=null, $from = null, $fromName = null) {
/* This function will be used to send email in my CakePHP application */
$this->Email->to = $to;
$this->Email->subject = env('SERVER_NAME') . ' – ' . $subject;
$this->Email->from = $fromName.' <'. $from.'>';
$this->Email->template = 'default';
$this->Email->additionalParams = '-fnoreply@yourdomain.com';
/* the above line is required to remove 'mailed-by' header' */
$this->Email->sendAs = 'both'; // you probably want to use both :)
return $this->Email->send($view);
}
Done.
Note again, whenever you use CakePHP Email Component, just add one extra line:
$this->Email->additionalParams = '-fnoreply@yourdomain.com';
And you can safely remove that annoying 'mailed-by' header.
That's it.
Just a guess, noreply@yourdomain.com is NOT essential. You may change it to anything you want.
Take care.
Responses awaited.
This was very useful.
ReplyDeleteThanks so much!
This was very helpful.
ReplyDeleteThank you so much!
Thanks.
ReplyDelete