dphe5602 2017-11-16 01:26
浏览 34
已采纳

为什么不在此代码中发送电子邮件? Magento的

I am trying to send a email for a user when he fill a form and click the submit.I have created a controller in Magento and included the following code

public function sendMailAction(){
    $html="put your html content hereblah blah";
    $mail = Mage::getModel('core/email');
    $mail->setToName('Your Name');
    $mail->setToEmail('sadeeenadeee@gmail.com');
    $mail->setBody('Mail Text / Mail Content');
    $mail->setSubject('Mail Subject');
    $mail->setFromEmail('Sender Mail Id');
    $mail->setFromName("Msg to Show on Subject");
    $mail->setType('html');// YOu can use Html or text as Mail format

    try {
        $mail->send();
        Mage::getSingleton('core/session')->addSuccess('Your request has been sent');
        $this->_redirect('');
    }
    catch (Exception $e) {
        Mage::getSingleton('core/session')->addError('Unable to send.');
        $this->_redirect('');
    }
    }

This is the function I am planning to use to send the email.Above controller function is called for the click of the submit button. Then I configured the outgoing SMTP email in Magento admin panel.

System > Configuration-> Mail Sending Settings

I followed the above path and added the HOST and PORT in the Mail Sending Settings and saved the config.HOST and PORT are obtained from the email service provider.But when a user fills the form and click the submit,rather than sending a email browser tries to launch a app saying that,

THIS LINK NEEDS TO BE OPEN WITH AN APPLICATION

Can someone help me please? I AM WORKING ON A HOSTED SITE

展开全部

  • 写回答

1条回答 默认 最新

  • duanruoyu6675 2017-11-16 04:53
    关注
    $emailTemplateVariables = array();
    $EmailSenderName="Email Sender Name";
    $EmailId="semder Email";
                $emailTemplateVariables['key1'] = "data1";
                $emailTemplateVariables['key2'] = "data2";
    
    
                /* sent mail to //recepient  */
                $recipientEmail="abcd@xyz.com";
    
                $sender = Array('name' => $EmailSenderName,
                'email' => $EmailId);
                $emailName = 'Email Name';
                $translate = Mage::getSingleton('core/translate');
                $emailTemplate  = Mage::getModel('core/email_template')
                            ->loadDefault('Any_email_template');
    
                    $emailTemplate->setSenderName($EmailSenderName)
                    ->setSenderEmail($EmailId)
                    ->setTemplateSubject($emailName);
                    $emailstatus=$emailTemplate->send($recipientEmail, $emailName, $emailTemplateVariables);
    
    
    
                $translate->setTranslateInline(true);
                if($emailstatus) {
    //email send successfully
    
                }
                else {
    
                //something went wrong
                }
    

    Please confirm that any mails in que for that enter the terminal command mailq

     $emailTemplate  = Mage::getModel('core/email_template')->load(1);   //1 is Transactional Emails id
    

    if you want to try default the above

    展开全部

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部