как отправлять электронную почту с localhost с помощью codeigniter?

function sendMail() { $config = Array( 'protocol' => 'smtp', 'smtp_host' => 'ssl://smtp.googlemail.com', 'smtp_port' => 465, 'smtp_user' => 'xxx@gmail.com', 'smtp_pass' => 'xxx', 'mailtype' => 'html', 'charset' => 'iso-8859-1', 'wordwrap' => TRUE ); $message = 'test'; $this->load->library('email', $config); $this->email->set_newline("\r\n"); $this->email->from('xxx@gmail.com'); $this->email->to('xyz@gmail.com'); $this->email->subject('testing'); $this->email->message($message); if($this->email->send()) { echo 'Email sent.'; } else { show_error($this->email->print_debugger()); } } 

Это мой код, я пытаюсь отправить электронную почту с localhost с помощью codeigniter, я получил сообщение «Отправлено по электронной почте». но я не получил почту в учетной записи gmail.

Solutions Collecting From Web of "как отправлять электронную почту с localhost с помощью codeigniter?"

  $config = Array( 'protocol' => 'smtp', 'smtp_host' => 'ssl://smtp.googlemail.com', 'smtp_port' => 465, 'smtp_user' => 'xxx@gmail.com',// your mail name 'smtp_pass' => '*****', 'mailtype' => 'html', 'charset' => 'iso-8859-1' 'wordwrap' => TRUE ); 

тогда

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

Настройки почты в XAMPP (Impotent)

 $this->email->from('mygmail@gmail.com', 'myname');//your mail address and name $this->email->to('target@gmail.com'); //receiver mail $this->email->subject('testing'); $this->email->message($message); $this->email->send(); //sending mail 

Конфигурация в sendmail.ini

путь c:\xampp\sendmail\sendmail.ini

Конфигурации

 [sendmail] smtp_server=smtp.gmail.com smtp_port=25 error_logfile=error.log debug_logfile=debug.log auth_username=myemail@gmail.com auth_password=yourgmailpassword force_sender=myemail@gmail.com 

в php.ini

путь c:\xampp\xampp\php\php.ini

 [mail function] sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t" 

Я вижу, что вам не хватает $this->email->initialize($config); Также убедитесь, что вы настроили свои настройки электронной почты, а localhost еще не работает.

Также $config = Array( изменение в $config = array(

Заменить почтовый ящик Gmail "

'smtp_host' => 'ssl://smtp.googlemail.com'

С

'smtp_host' => 'ssl://smtp.gmail.com'

Код

 function send_mail() { $config = array( 'protocol' => 'smtp', 'smtp_host' => 'ssl://smtp.gmail.com', 'smtp_port' => 465, 'smtp_user' => 'xxx@gmail.com', 'smtp_pass' => 'xxx', 'mailtype' => 'html', 'charset' => 'iso-8859-1', 'wordwrap' => TRUE ); $this->load->library('email', $config); $this->email->initialize($config); // Add $this->email->from('xxx@gmail.com'); $this->email->to('xyz@gmail.com'); $this->email->subject('testing'); $message = 'test'; $this->email->message($message); if($this->email->send()) { echo 'Email sent.'; } else { print_r($this->email->print_debugger()); } } 

Электронная почта Не может быть отправлена ​​локально. Этот метод может быть протестирован на тестовом сервере.

  $CI =& get_instance(); $CI->load->library('email'); $CI->email->initialize(get_email_config()); $CI->email->from($data['email_from'],WEBSITE_TITLE); // Constant is define which exist email $CI->email->to($data['email_to']); if(isset($data['bcc']) && !empty($data['bcc'])){ $CI->email->bcc($data['bcc']); }else{ $CI->email->bcc('other_email'); } if(isset($data['upload'])&& !empty($data['upload'])){ $CI->email->attach($data['upload']); } $CI->email->subject($data['subject']); $CI->email->message($data['body']); $CI->email->send(TRUE);