dongren9739 2014-11-08 03:49
浏览 49
已采纳

使用codeigniter库函数发送的邮件作为垃圾邮件发送

I am using codeigniter framework. While send mails using codeigniter mail functions, mail is delivered as spam, i dont know why this happens, i am using code as:

    $this->load->library('email');
    if($fromname==''){$fromname='MySystem';}
    if($from==''){$from='noreply@gmail.com';}
    if($reply==''){$reply=$from;}
    $config = array(
    'protocol' => 'smtp',
    'smtp_host' => host,
    'smtp_port' => port,
    'smtp_crypto' => 'ssl',
    'smtp_user' => user_nam,
    'smtp_pass' => pwd,
    'mailtype'  => 'html', 
    'charset'   => 'utf-8',
    'wordwrap' => TRUE
   );
    $this->email->initialize($config);
    $this->email->from($from, $fromname);
    $this->email->reply_to($reply, $fromname);
    foreach($result as $row){
    $this->email->to($to);
    $this->email->subject($subject);
    $this->email->message($message1);

    $this->email->send();
    }

By using this code, a mail is sending to a group of users. This mails are received as spam mails. Is this because of some error in code or a server issue?

  • 写回答

2条回答 默认 最新

  • drd43058 2014-11-08 06:13
    关注

    The main problem is likely your from address. When sending email, you are saying the sender is noreply@gmail.com. When your email is received, the service will look up Gmail's SPF (http://en.wikipedia.org/wiki/Sender_Policy_Framework) DNS record to see if the server that sent the email (your server) is a server which Gmail say is a permitted sender, which of course it's not. Since that check fails, the email is very likely to end up in spam.

    The way to fix that is to set your from address to a real domain, e.g. noreply@yourdomain.com. Then you need to set an SPF record so that your server is a trusted sender for that domain. There are heaps of tutorials out there to help with that, but you could simply use this as a TXT record on yourdomain.com:

    v=spf1 ip4:<your server IP> ~all
    

    If you send email from yourdomain.com from other services (e.g. Google Apps) you'll want to add rules for that too.

    Even with that, your emails aren't guaranteed to stay out of spam. If the content of the messages is simplistic and spam-like, or if you don't include an unsubscribe link, you could also end up in spam.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 易语言把MYSQL数据库中的数据添加至组合框
  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况