2013-09-03 41 views
16
public function sendemail(){ 
    $config = Array( 
    'protocol' => 'smtp', 
    'smtp_host' => 'ssl://smtp.googlemail.com', 
    'smtp_port' => 465, 
    'smtp_user' => '[email protected]', 
    'smtp_pass' => 'password',); 

    $this->load->library('email', $config); 
    $this->email->set_newline("\r\n"); 
    $this->email->from('[email protected]', 'Name'); 
    $this->email->to('[email protected]'); 
    $this->email->subject(' My mail through codeigniter from localhost '); 
    $this->email->message('Hello World…'); 
    if (!$this->email->send()) { 
    show_error($this->email->print_debugger()); } 
    else { 
    echo 'Your e-mail has been sent!'; 
    } 
} 

tôi nhận được một lỗi khi tôi sử dụng codeigniter để gửi email:Gửi email bằng cách sử dụng thư viện CodeIgniter qua localhost

Message: mail() [function.mail]: Failed to connect to mailserver at 
"localhost" port 25, verify your "SMTP" and "smtp_port" setting in 
php.ini or use ini_set(). 

Unable to send email using PHP mail(). Your server might not be 
configured to send mail using this method. 

Tôi đang làm gì sai?

Trả lời

29

Vui lòng kiểm tra mã làm việc của tôi.

function sendMail() 
{ 
    $config = Array(
    'protocol' => 'smtp', 
    'smtp_host' => 'ssl://smtp.googlemail.com', 
    'smtp_port' => 465, 
    'smtp_user' => '[email protected]', // change it to yours 
    'smtp_pass' => 'xxx', // change it to yours 
    'mailtype' => 'html', 
    'charset' => 'iso-8859-1', 
    'wordwrap' => TRUE 
); 

     $message = ''; 
     $this->load->library('email', $config); 
     $this->email->set_newline("\r\n"); 
     $this->email->from('[email protected]'); // change it to yours 
     $this->email->to('[email protected]');// change it to yours 
     $this->email->subject('Resume from JobsBuddy for your Job posting'); 
     $this->email->message($message); 
     if($this->email->send()) 
    { 
     echo 'Email sent.'; 
    } 
    else 
    { 
    show_error($this->email->print_debugger()); 
    } 

} 
+0

có cấu hình nào trong máy chủ cục bộ để email có thể được gửi không? –

+0

vâng bạn phải bật openssl trong localhost –

+0

tại sao mọi lúc tôi thay đổi $ this-> email-> from ('[email protected] '); đến địa chỉ khác như yahoo, email tôi nhận được luôn được gửi từ 'tôi' thay cho người gửi? –

2

Tôi đã gặp vấn đề tương tự và tôi đã giải quyết bằng cách sử dụng postcast server. Bạn có thể cài đặt nó cục bộ và sử dụng nó.

Các vấn đề liên quan