【发布时间】: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 <span style="color: #fa233d;">|</span> +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;"> <span style="color: #fa233d;">|</span> 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