This is the function that carries out send mail functionality. I am one hundred percent sure that, this method is calling correctly.
public function sendMail($data)
{
try {
// Gets the current store's id
$storeId = Mage::app()->getStore()->getStoreId();
$templateId = $data['mail_template'];
$mailer = Mage::getModel('core/email_template_mailer');
$emailInfo = Mage::getModel('core/email_info');
//set receipient address
$emailInfo->addTo(trim($data['mail_to']));
$mailer->addEmailInfo($emailInfo);
// Set all required params and send emails
$mailer->setSender(trim($data['mail_from']));
$mailer->setStoreId($storeId);
$mailer->setTemplateId($templateId);
$mailer->setTemplateParams(array(
'subject' => trim($data['mail_sub']),
'content' => trim($data['mail_content'])
));
if ($mailer->send()) {
Mage::getSingleton('core/session')->addSuccess('Successfully Email Sent');
return true;
}
} catch (Exception $e) {
Mage::throwException($e);
return false;
}
return true;
}
Please note I didn't get any exception while doing this. Also there is no log errors. When I prints $mailer
variable (holds the instance of Mage_Core_Model_Email_Template_Mailer
) just above send
method, I am getting this as output.
Mage_Core_Model_Email_Template_Mailer Object
(
[_emailInfos:protected] => Array
(
[0] => Mage_Core_Model_Email_Info Object
(
[_bccNames:protected] => Array
(
)
[_bccEmails:protected] => Array
(
)
[_toNames:protected] => Array
(
[0] =>
)
[_toEmails:protected] => Array
(
[0] => [email protected]
)
[_data:protected] => Array
(
)
[_hasDataChanges:protected] =>
[_origData:protected] =>
[_idFieldName:protected] =>
[_isDeleted:protected] =>
[_oldFieldsMap:protected] => Array
(
)
[_syncFieldsMap:protected] => Array
(
)
)
)
[_data:protected] => Array
(
[sender] => [email protected]
[store_id] => 0
[template_id] => send_mail_mailer_mail_template
[template_params] => Array
(
[subject] => Test Subject
[content] => askldjflkajsdkf asdjfkl asdjfasdklf sdjklsdjksdjkljsdklfjsd fjklj fkljsakl fdjklsdjklfjasdkljf
)
)
[_hasDataChanges:protected] => 1
[_origData:protected] =>
[_idFieldName:protected] =>
[_isDeleted:protected] =>
[_oldFieldsMap:protected] => Array
(
)
[_syncFieldsMap:protected] => Array
(
)
)
Here you can see that, every value is setting correctly here (AFAIK). But I cant see any mails received at the email address [email protected]
.
What I have done wrong here ? At least give me some hints in order tackle the real problem. Thanks
Edit 1
I narrowed down my problem and ended up here Mage_Core_Model_Email_Template::isValidForSend()
. This method returns false
in my case. When I dig more there., I found out that, the line
$this->getTemplateSubject()
is responsible for the false
value. In my initial investigation, this returns fasle
only if I dont have a subject set with my mail template. But I have subject included in my template like this.
<!--@subject {{var subject}} @-->
and I can see this value when print the instance of Mage_Core_Model_Email_Template
in its _data
array as like this.
[_data:protected] => Array
(
[sent_success] =>
[template_type] => 2
[template_subject] => {{var subject}}
[orig_template_variables] => {"store url=\"\"":"Store Url","var logo_url":"Email Logo Image Url","var logo_alt":"Email Logo Image Alt","var content":"Email Content"}
[template_styles] => body,td { color:#2f2f2f; font:11px/1.35em Verdana, Arial, Helvetica, sans-serif; }
[template_text] =>
Please note the template_subject
. Dont know how to go further. If you have any thoughts please share