【问题标题】:HTML Template message in codeigniter emailcodeigniter 电子邮件中的 HTML 模板消息
【发布时间】:2017-10-06 11:49:09
【问题描述】:

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

电子邮件模板.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模板,则邮件不会发送

【问题讨论】:

  • 你为邮件类型配置了什么?
  • @azinkey 其 html
  • 试试 $this->email->set_newline("\r\n");
  • 您使用哪个邮件服务器发送电子邮件?
  • @bilal 它的 smtp.mailhostbox.com

标签: php html codeigniter email


【解决方案1】:

在您的配置中添加邮件类型

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

http://codeigniter.com/user_guide/libraries/email.html

【讨论】:

  • 试试这个$this-&gt;email-&gt;set_mailtype("html");
  • 我认为它与邮件类型无关。我尝试发送类似 $this->email->message('
    Hai
    ') 的消息进行测试。它的工作
  • 实际上问题出在超链接上。我刚刚从我的 html 代码中删除了它们,然后它工作正常。但是我怎样才能用这个模板添加这个链接
【解决方案2】:

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 中放入的相同邮件来配置发件人

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

【讨论】:

    【解决方案3】:

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

    感谢大家的宝贵建议。

    【讨论】:

      猜你喜欢
      • 2013-04-24
      • 2012-04-28
      • 2021-02-06
      • 2013-05-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-16
      • 2017-09-22
      相关资源
      最近更新 更多