CI框架发送邮件

最近搞房源举报功能,截图如下:



 CI框架有发送邮件类:具体的可以看手册,关于邮件的配置文件,我放在单独的文件里,方便以后维护

 文件名为:email.php,这个文件保存到application/config/email.php,然后在控制器里加载$this->load->library('email'),这样就不需要使用$this->email->initialize()函数来初始化参数了

<?php
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'smtp.163.com';
$config['smtp_user'] = 'email地址';
$config['smtp_pass'] = '*******';
$config['mailtype'] = 'html';
$config['validate'] = true;
$config['priority'] = 1;
$config['crlf']  = "\r\n";
$config['smtp_port'] = 25;
$config['charset'] = 'gb2312';
$config['wordwrap'] = TRUE;

 

视图关键代码:

 <form action="<?php echo base_url();?>content/sendMail.html" method="post">
 <input type="hidden" name="number" value="<?php echo $this->uri->segment(3);?>" />
 <input type="hidden" name="url" value="<?php echo $_SERVER['PHP_SELF'];?>" />
  <table>
    <tr>
      <td colspan="2">您要投诉的帖子,编号<span style="color:red;"><?php printf('ZB%07s',$this->uri->segment(3));?></span></td>
    </tr>
    <tr>
      <td><input name="warn" type="radio" value="1" checked="checked"/> 中介冒充个人</td>
      <td><input name="warn" type="radio" value="2" /> 联系电话虚假</td>
    </tr>
    <tr>
      <td><input name="warn" type="radio" value="3" /> 虚假、违法信息</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td colspan="2">
        <textarea name="cont" cols="" rows="" style="width:280px;height:70px;"></textarea>
      </td>
    </tr>
    <tr>
      <td><input name="complaint" type="submit" value="投诉" /></td>
      <td>&nbsp;</td>
    </tr>
  </table>
  </form>

 控制器代码如下:

function sendMail(){
   $url='http://zufang.0551fangchan.com'.$this->input->post('url',true);
   $num=$this->input->post('number',true);
   $this->load->library('email');
   $warn=$this->input->post('warn',true);
   $content=$this->input->post('cont',true);
   if($warn===1){
    $type='中介冒充个人';
   }elseif($warn===2){
    $type='联系电话虚假';
   }elseif($warn===3){
    $type='虚假、违法信息';
   }
  $title="HouseID:{$num} have a problem!";
  $message="网友举报编号为:<span style='color:red'>{$num}</span>的房源:<br />原因是:<span style='color:red'>{$type}</span><br />举报内容:{$content}<br />链接如下:<a href=\"{$url}\" target='_blank'><span style='color:red'>点击查看举报房源</span></a> ";
  $this->email->from('services0551@163.com', '网友');
  $this->email->to('442700091@qq.com');
  $this->email->subject($title);
  $this->email->message($message);
  if (!$this->email->send()){
   echo '发送邮件失败!';//这个地方可以加些跳转效果
   redirect($url);
  }else{
   echo '发送邮件成功';//这个地方可以加些跳转效果
   redirect($url);
  }
  } 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值