我目前正在使用此方法发送电子邮件:
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协议。
但大多数邮件都是收件箱。 我想添加电子邮件的文本版本,以改善电子邮件的传递。 我怎么能这样做?
非常感谢!
答案 0 :(得分:1)
这是我的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);
答案 1 :(得分:1)
通过CodeIgniter库在邮件中发送HTML和纯文本部分:您可以使用set_alt_message()
函数设置自己的部分,但它会通过剥离HTML标记自动生成一个(请参阅{{1} })函数,所以这实际上可能不会为你改变。
因此,在通过垃圾邮件过滤器方面,您是否设置了an SPF record?
我写了一篇关于此的博客文章可能很有用:"Getting your web server mail through spam filters"
答案 2 :(得分:0)
尝试使用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());
}