繁体   English   中英

Codeigniter电子邮件中的HTML模板消息

[英]HTML Template message in codeigniter email

我正在使用codeigniter电子邮件库发送电子邮件。 我的消息包含html代码。 但无法发送电子邮件,而是显示错误消息,例如“此消息已被我们的垃圾邮件过滤器拒绝”。 这是我的代码:

email-template.php

<html>
<body>
    <div style="background-color: #f3f3f3; max-width: 650px; margin: 0 auto; box-shadow: 0px 0px 25px rgba(0, 0, 0, 0.25);">
        <!-- header section -->
        <div style="/*border-bottom: 5px solid #cc342f;*/ border-bottom: 5px solid #fa233d; background-color: #f4f1f1; padding: 20px;">
            <div style="text-align: left;">
                <img src="<?php echo base_url()?>assets/images/logo.png" alt="test">
            </div>  
        </div>
        <!-- content section -->
        <div style="padding: 20px 25px; text-align: justify; overflow: hidden; position: relative;">        
            <p style="font-family: Arial, Helvetica, sans-serif; font-weight: bold; color: #fa233d;">
                    Hi <?php echo $user;?>,
            </p>
            <p style="font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-weight: 100; color: #1b1b1b; line-height: 24px;">
                You recently requested to reset your password for your ***** account.
            </p>
            <p style="font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-weight: 100; color: #1b1b1b; line-height: 24px;">
                Click the button below to reset your password.
            </p>
            <p style="font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-weight: 100; color: #1b1b1b; line-height: 24px;">
                <a href="">Reset Password</a>
            </p>
            <p style="font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-weight: 100; color: #1b1b1b; line-height: 24px;">
                If you did not request a password reset, please ignore this mail. 
            </p>
            <p style="font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-weight: 100; color: #1b1b1b; line-height: 24px;">
                Thanks,
            </p>
            <p style="font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-weight: 100; color: #1b1b1b; line-height: 24px;">
                *********
            </p>

            <!-- Disclaimer -->
            <p style="font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-weight: 100; color: #1b1b1b; line-height: 14px; border: 1px solid #ddd; padding: 10px">
                <small>
                    If you have trouble clicking the reset button, copy and paste below URL in your web browser. <br/>
                    <a href="<?php echo base_url().'Home/resetPassword/'.$email.'/'.$password?>">Reset Password</a>

                </small>
            </p>

        </div>  

        <!-- footer section -->
        <div style="border-top: 3px solid #fa233d; background-color: #f4f1f1; padding: 10px 25px; text-align: right">

            <p style="margin: 0; font-family: Arial, Helvetica, sans-serif; font-size: 11px; color: #1d1d1d; text-decoration: none; display: inline-block;">+91 1231 123123&nbsp; <span style="color: #fa233d;">|</span> &nbsp;+91 123123 12313 </p>

            <a href="<?php echo base_url()?>" style="font-family: Arial, Helvetica, sans-serif; font-size: 11px; color: #1d1d1d; text-decoration: none; display: inline-block;">&nbsp; <span style="color: #fa233d;">|</span> &nbsp;Visit Us</a>

        </div>
    </div>
</body>

home.php控制器

public function forgotPassword() { 
    $email = $this->input->post('email');    
    $password = ****** 
    $user = $this->Home_model->findUsernameByEmail($email);
    $data = array('email' => $email,
                    'password' => $password,
                    'user' => $user);
    $body = $this->load->view('templates/forgot-password', $data, true);
    $result = $this->Home_model->forgotPassword($email, $body);    
    echo $result;
}

和Home_model.php

function forgotPassword($email, $message){ //print_r( $message); exit;
    $this->db->where('LoginEmailID', $email);
    $result = $this->db->get('usermaster_tbl')->row_array(); 
    if($result['UserID'] != 0 && $result['UserID'] != ''){                
        $this->email->message($message);
        $this->email->to($email);
        $this->email->from('****@****.in', 'Administrator');
        $this->email->subject('Reset Password');
        $this->email->send();
        print_r($this->email->print_debugger());
        return 1;            
    }
    else{            
        return 0;
    }

}

如果我使用除html代码以外的消息,则它正在工作。 但是,如果使用了html模板,则不会发送邮件

在配置中添加邮件类型

$config = Array(
'mailtype' => 'html',
...etc...
);

请参阅http://codeigniter.com/user_guide/libraries/email.html

1-在位于Applications / config / email.php的配置文件中,必须输入以下内容

 $config['protocol'] = 'smtp';
 $config['charset'] = 'utf8';
 $config['wordwrap'] = TRUE;
 $config['smtp_host'] = 'ssl://smtp.googlemail.com';
 $config['smtp_port'] = 465;
 $config['smtp_user'] = "youemail@gmail.com";
 $config['smtp_pass'] = "yourpass";
 $config['newline'] = "\r\n";
 $config['priority'] = 1;
 $config['mailtype'] = 'html'; //very important to send email html

2-为了不将您的电子邮件检测为垃圾邮件,您必须使用与配置文件email.php中相同的邮件来配置from。

$this->email->from('myemail@gmail.com', 'Administrator');

我找到了答案。 实际上问题出在图像和锚定模板中使用的url。 我正在使用本地服务器对其进行测试,因此该链接已被邮件服务器安全性阻止。 我将其更改为现场网址。 现在问题解决了。

谢谢大家的宝贵建议。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM