2014-03-03 28 views
1

我目前使用這種方法可以發送電子郵件:笨發送HTML和文本電子郵件

public function send_mail($data) 
{ 
    $message = $this->load->view($data['template'], $data, true); 
    $this->email->clear(); 
    $this->email->from("[email protected]", $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協議。

但是大多數郵件都會發往垃圾郵箱.. 我想添加電子郵件的文本版本以改善電子郵件的傳遞。 我怎樣才能做到這一點?

非常感謝!

+1

如果從郵件不匹配您發送電子郵件域的地址,它可能會去的垃圾郵件。 –

+0

我知道,但是表單域的地址與我發送郵件的域相同 – Mazeltov

回答

1

這裏是我的崗位爲核心PHP,你可以很容易地把它變成笨,

Universal Send email html or plain text php

<?php 

     $from = "a asd"; 
     $email = "[email protected]"; 
     $email = "[email protected]"; 

       $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); 
+0

這並沒有提供問題的答案。要批評或要求作者澄清,請在其帖子下方留言。 –

+0

@ Klaster_1,編輯後。 –

+0

謝謝你的回答,但是我使用的是sendmail,而不是php的郵件功能 – Mazeltov

0

嘗試與谷歌郵件的SMTP

$this->load->library('email'); 

$config = Array( 
    'protocol' => 'smtp', 
    'smtp_host' => 'ssl://smtp.googlemail.com', 
    'smtp_port' => 465, 
    'smtp_user' => '[email protected]', // 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('[email protected]'); 
$this->email->to('[email protected]'); 

$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()); 
} 
1

發送在發送方面通過CodeIgniter庫的郵件中的HTML和純文本部分:您可以使用set_alt_message()函數來設置自己的函數,但它會自動生成一個剝離HTML標籤(請參閱_get_alt_message())的功能,因此這可能不會爲您改變事物。

因此,在越過垃圾郵件過濾器方面,您是否設置了an SPF record

我寫這個可能是有用的一篇博客文章:"Getting your web server mail through spam filters"