【问题标题】:Codeigniter send html and text emailsCodeigniter 发送 html 和文本电子邮件
【发布时间】:2014-04-04 06:44:41
【问题描述】:

我目前正在使用这种方法发送电子邮件:

public function send_mail($data)
{
    $message = $this->load->view($data['template'], $data, true);
    $this->email->clear();
    $this->email->from("no-reply@mysite.com", $this->config->item('site_title', 'ion_auth'));
    $this->email->to($data['email']);
    $this->email->subject($this->config->item('site_title', 'ion_auth') . ' - ' . $data['subject']);
    $this->email->message($message);
    if ($this->email->send() == TRUE)
    {
        return true;
    }else
    {
        return false;
    }
}

我使用 SMTP 协议。

但是大多数邮件都会进入垃圾邮件收件箱.. 我想添加电子邮件的文本版本以改进电子邮件的传递。 我该怎么做?

非常感谢!

【问题讨论】:

  • 如果邮件的发件人地址与您发送邮件的域不匹配,它可能会进入垃圾邮件。
  • 我知道,但是表单域地址与我发送邮件的域相同

标签: php codeigniter email


【解决方案1】:

关于通过 CodeIgniter 库在邮件中发送 HTML 和纯文本部分:您可以使用 set_alt_message() 函数自行设置,但它会通过剥离 HTML 标签自动生成一个(参见 _get_alt_message())函数,所以这实际上可能不会改变你的事情。

那么就通过垃圾邮件过滤器而言,您是否设置了an SPF record?

我写了一篇可能有用的博客文章:"Getting your web server mail through spam filters"

【讨论】:

    【解决方案2】:

    尝试用google mail smtp发送

    $this->load->library('email');
    
    $config = Array(   
        'protocol' => 'smtp',
        'smtp_host' => 'ssl://smtp.googlemail.com',
        'smtp_port' => 465,
        'smtp_user' => 'abc@gmail.com', // change it to yours
        'smtp_pass' => '*******', // change it to yours
        'mailtype' => 'html', // text
        'charset' => 'iso-8859-1',
        'newline' => '\r\n',
        'wordwrap' => TRUE
    );
    
    $this->email->initialize($config);
    $this->email->from('abc@gmail.com'); 
    $this->email->to('test@gmail.com');
    
    $this->email->subject('Test mail');
    $this->email->message('Test HTML Data');
    if($this->email->send())
    {
    
        echo "Mail sent";
    }
    else
    {
        show_error($this->email->print_debugger());
    }
    

    【讨论】:

      【解决方案3】:

      这是我的 Core PHP 帖子,您可以轻松将其更改为 codeigniter,

      Universal Send email html or plain text php

      <?php
      
              $from = "a asd"; 
              $email = "sd@dfsds.com";
              $email = "sdsad@sdfsdf.com";
      
                      $semi_rand = md5(time());
                      $mime_boundary = "==MULTIPART_BOUNDARY_$semi_rand";
                      $mime_boundary_header = chr(34) . $mime_boundary . chr(34);
                      $boundary = "nextPart";
                      $headers = "From: \"".$from."\" <".$email.">\n";
      
                      $headers .=  "To: ". $new_to ."\n";
      
                      $headers .= "Reply-To: \"". $from. "\" <" . $email . ">\r\n";
                      $headers .= "Return-Path: <". $email .">\r\n";
                      $headers .= "MIME-Version: 1.0\r\n";
                      $headers .= "Content-Type: multipart/alternative;\n boundary=" . $mime_boundary_header ;
                      $headers .= "\n--$boundary\n"; // beginning \n added to separate previous content
                      $headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
                      $headers .= "\n--$boundary\n";
                      $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
                      $headers .= "Content-Transfer-Encoding:base64\r\n";
      $body = "
      
      --$mime_boundary
      Content-Type: text/plain; charset=us-ascii
      Content-Transfer-Encoding: 7bit
      
      ". strip_tags($messageBody) ."
      
      --$mime_boundary
      Content-Type: text/html; charset=us-ascii
      Content-Transfer-Encoding:base64
      
      ". chunk_split(base64_encode($messageBody)) ."
      
      --$mime_boundary--";
      
      mail(null,$sub,$body,$headers,"-f".$email); 
      

      【讨论】:

      • 这并没有提供问题的答案。要批评或要求作者澄清,请在其帖子下方发表评论。
      • @Klaster_1,已编辑帖子。
      • 谢谢你的回答,但我用的是sendmail,不是php邮件功能
      • @Mazeltov , 未经测试的 Buttry, $plain_text_message = 'PLAIN TEXT message'; $this->email->set_alt_message($plain_text_message);
      猜你喜欢
      • 2011-10-02
      • 2013-01-07
      • 2019-08-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-10
      • 2016-07-28
      • 1970-01-01
      相关资源
      最近更新 更多