2014-01-20 1 views
1

Я пытаюсь отправить почту. его не дают ошибку, но не доставленную почтуКак отправить почту с localhost в php codeigniter?

 $config['smtp_host'] = "ssl://smtp.googlemail.com"; 
     $config['smtp_port'] = "456"; 
     $config['smtp_user'] = "[email protected]"; 
     $config['smtp_pass'] = "mypassword"; 
     $this->email->initialize($config); 

     $message = "my message"; 
     $this->email->from('[email protected]'); 
     $this->email->to('[email protected]'); 
     $this->email->subject('Testing'); 
     $this->email->message($message); 
     if($this->email->send()) 
     { 
       echo 'Email sent.'; 
     } 
     else 
     { 
       show_error($this->email->print_debugger()); 
     } 

его возвращения «Email отправить» но почта не доставляется

+0

проверьте папку со спамом, а также попытаться определить протокол в конфиге –

+0

изменить параметры SMTP в LOCALHOST php.ini используйте файл Gmail для отправки электронной почты –

ответ

0

Попробуйте это проверенный код.

function sendMail() 
    { 
     $config = Array(
     'protocol' => 'smtp', 
     'smtp_host' => 'ssl://smtp.googlemail.com', 
     'smtp_port' => 465, 
     'smtp_user' => '[email protected]', 
     'smtp_pass' => 'xxx', 
     '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]'); 
      $this->email->to('[email protected]'); 
      $this->email->subject('Your Subject'); 
      $this->email->message($message); 
      if($this->email->send()) 
     { 
      echo 'Email sent.'; 
     } 
     else 
     { 
     show_error($this->email->print_debugger()); 
     } 

    } 
0

вы можете сделать это с помощью phpmailer. Вы можете скачать его здесь PHPMailer

Теперь сделайте follwoing код на в вашей функции:

   public function sendmail() 
       { 
    require_once(APPPATH.'third_party/PHPMailer-master/PHPMailerAutoload.php'); 

       $mail = new PHPMailer; 
       $mail->isSMTP();       // Set mailer to use SMTP 
       $mail->Host = 'smtp.gmail.com';    // Specify main and backup SMTP servers 
       $mail->SMTPAuth = true;      // Enable SMTP authentication 
       $mail->Username = 'Email Address';   // SMTP username 
       $mail->Password = 'Email Account Password'; // SMTP password 
       $mail->SMTPSecure = 'tls';     // Enable TLS encryption, `ssl` also accepted 
       $mail->Port = 587;       // TCP port to connect to 

       $mail->setFrom('[email protected]', 'CodexWorld'); 
       $mail->addReplyTo('[email protected]', 'CodexWorld'); 
       $mail->addAddress('[email protected]'); // Add a recipient 
       $mail->addCC('[email protected]'); 
       $mail->addBCC('[email protected]'); 

       $mail->isHTML(true); // Set email format to HTML 

       $bodyContent = '<h1>How to Send Email using PHP in Localhost by CodexWorld</h1>'; 
       $bodyContent .= '<p>This is the HTML email sent from localhost using PHP script by <b>CodexWorld</b></p>'; 

       $mail->Subject = 'Email from Localhost by CodexWorld'; 
       $mail->Body = $bodyContent; 

       if(!$mail->send()) { 
        echo 'Message could not be sent.'; 
        echo 'Mailer Error: ' . $mail->ErrorInfo; 
       } else { 
        echo 'Message has been sent'; 
       } 
     } 

Если упаковывают ошибка синтаксиса пришел посетить here

Это отлично работает для меня.

0
$config['protocol'] = 'smtp'; 
    $config['smtp_host'] = 'ssl://smtp.gmail.com'; 
    $config['smtp_port'] = '465';       //ssl 
    $config['smtp_timeout'] = '7'; 
    $config['smtp_user'] = '[email protected]'; //gmail id 
    $config['smtp_pass'] = 'xxxx';   //gmail password 
    $config['charset'] = 'utf-8'; 
    $config['newline'] = "\r\n"; 
    $config['mailtype'] = 'html'; 
    $config['validation'] = TRUE; 
Смежные вопросы