dphe5602 2017-11-16 09: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 12: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

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

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。