开发者

Sending template emails in Magento

I'm creating a Magento Module that can be used to send emails in certain occasions of my website. I'm following the tutorial from Branko Ajzele and everything seems to work fine until I try to send the email where I get a false response from the Send function.

Below is the code I'm using along with the result returned:

public function sendAction() {

    /*
     * Loads the html file named 'custom_email_template1.html' from
     * app/locale/en_US/template/email/activecodeline_custom_email1.html
     */
    $emailTemplate  = Mage::getModel('core/email_template')
                            ->loadDefault('custom_email_template1');                                
//        var_dump(Mage::getModel('core/email_template'));
    //Create an array of variables to assign to template
    $emailTemplateVariables = array();
    $emailTemplateVariables['myvar1'] = 'Branko';
    $emailTemplateVariables['myvar2'] = 'Ajzele';
    $emailTemplateVariables['myvar3'] = 'ActiveCodeline';

    /**
     * The best part <img src="http://inchoo.net/wp-includes/images/smilies/icon_smile.gif" alt=":)" class="wp-smiley">
     * Opens the activecodeline_custom_email1.html, throws in the variable array
     * and returns the 'parsed' content that you can use as body of email
     */

    /*
     * Or you can send the email directly,
     * note getProcessedTemplate is called inside send()
     */
    $emailTemplate->setSenderName('my name');
    $emailTemplate->setSenderEmail('example@domain.com');
    $emailTemplate->setTemplateSubject('STATUS CHANGED');

    var_dump($emailTemplate->send('example@domain.com'));
    echo "<br>";
    var_dump($emailTemplate);

    exit("test");

}

The var_dump given by var_dump($emailTemplate); returns the object with all the information correctly as shown below:

bool(false)
object(Gp_Notify_Model_Email_Template)#82 (19) { ["_templateFilter:protected"]=> NULL ["_preprocessFlag:protected"]=> bool(false) ["_mail:protected"]=> NULL ["_designConfig:protected"]=> NULL ["_emulatedDesignConfig:protected"]=> bool(false) ["_initialEnvironmentInfo:protected"]=> NULL ["_eventPrefix:protected"]=> string(13) "core_abstract" ["_eventObject:protected"]=> string(6) "object" ["_resourceName:protected"]=> string(19) "core/email_template" ["_resource:protected"]=> NULL ["_resourceCollectionName:protected"]=> string(30) "core/email_template_collection" ["_cacheTag:protected"]=> bool(false) ["_dataSaveAllowed:protected"]=> bool(true) ["_isObjectNew:protected"]=> NULL ["_data:protected"]=> array(6) { ["template_type"]=> int(2) ["template_subject"]=> string(14) "STATUS CHANGED" ["template_text"]=开发者_StackOverflow中文版> string(208) "
ActiveCodeline custom email example by Branko Ajzele

Hi there {{var myvar1}} {{var myvar2}} from {{var myvar3}}. This is just some example template to test custom email module.
" ["template_id"]=> string(22) "custom_email_template1" ["sender_name"]=> string(7) "my name" ["sender_email"]=> string(15) "phil@gproxy.com" } ["_hasDataChanges:protected"]=> bool(true) ["_origData:protected"]=> NULL ["_idFieldName:protected"]=> NULL ["_isDeleted:protected"]=> bool(false) } test

The thing is that although everything seems to go well the send function returns false and of course I never get to receive the email. Is there something I'm forgetting to do like any configuration in the backend or something?

---- UPDATE ----

After some investigation I realized that there are no emails reaching their destination at all in my Magento installation which I thought they were, so figured I should start from there.

I have already added all the emails in the backend. I checked the Locale (language) and changed it to english/US (which I read could be an issue). Any advise?


Are u trying it on the localhost or the live site. If you are trying in the localhost then you need to correct in the php.ini file for the email setting.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜