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

图片转代码服务由CSDN问答提供 功能建议

我正在尝试为用户填写表单并单击提交时发送电子邮件。我创建了一个 Magento中的控制器并包含以下代码

  public function sendMailAction(){
 $ html =“将你的html内容放在hereblah blah”; 
 $ mail = Mage ::  getModel('core / email'); 
 $ mail-> setToName('Your Name'); 
 $ mail-> setToEmail('sadeeenadeee@gmail.com'); 
 $ mail-> setBody  ('邮件文本/邮件内容'); 
 $ mail-> setSubject('邮件主题'); 
 $ mail-> setFromEmail('发件人邮件ID'); 
 $ mail-> setFromName(  “Msg to Subject on Subject”); 
 $ mail-> setType('html'); //你可以使用Html或文本作为邮件格式
 
尝试{
 $ mail-> send()  ; 
 Mage :: getSingleton('core / session') - > addSuccess('您的请求已被发送'); 
 $ this-> _redirect(''); 
} 
 catch(Exception $  e){
 Mage :: getSingleton('core / session') - > addError('无法发送。'); 
 $ this-&  gt; _redirect(''); 
} 
} 
   
 
 

这是我计划用来发送电子邮件的函数。调用控制器函数 单击提交按钮。 然后我在Magento管理面板中配置了外发SMTP电子邮件。

系统> 配置 - > 邮件发送设置

我按照上述路径添加了邮件发送设置中的 HOST PORT 并保存 config.HOST和PORT是从电子邮件服务提供商处获得的。但是当用户填写表单并单击提交时,而不是发送电子邮件浏览器尝试启动应用程序说明,​​

此链接需要通过应用程序打开

有人可以帮助我吗? 我正在努力 主机网站

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

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

    打赏 评论

相关推荐 更多相似问题