2017-05-08 80 views
1

我想通過使用下面的CodeIgniter代碼將電子郵件從wampserver「localhost」發送到我的gmail帳戶。從本地發送電子郵件中的問題[WAMP]在CI

public function emailsent_info() 
    { 
     $config = array(
     'protocol' => 'smtp', 
     'smtp_host' => 'ssl://smtp.googlemail.com', 
     'smtp_port' => 465, 
     'smtp_user' => '[email protected]', 
     'smtp_pass' => 'XXXXXXX', 
      ); 

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

    //$this->email->set_newline("\r\n"); 

    $this->email->from('[email protected]', 'Deepak Saar'); 
    $this->email->to('[email protected]'); 
    $this->email->subject('Matters Mostly Good'); 

    $this->email->message('Its Working Now, Great'); 

    if($this->email->send()) 
    { 
     echo 'Your Email Sent Successfully'; 
    } 
    else 
    { 
     echo $this->email->print_debugger(); 
    } 

} 我沒有做在CI的任何其他文件的任何其他修改呢。當我運行該項目時,服務器回答如下: The Server Replied with this message 我在哪裏出錯?

+1

的LocalServer無法發送郵件兄弟 – Exprator

+0

@Exprator,有一些參考,我通過網絡看到發送電子郵件通過ci – Keynes

+1

你不能從本地服務器兄弟。 – Exprator

回答

0

你不能沒有某些配置從本地主機發送一封電子郵件,

我個人使用SMTP4DEV當我在本地主機正在編碼,

如果硬要發送實時電子郵件這也許能幫助您:如果您使用的是本地SMTP郵件,那麼你必須設置SMTP設置你的WAMP的, 如果使用PHPMailer的它使用起來非常簡單CONFIGURE SENDMAIL WITH WAMP

1

,下載PHPMailer的following link,放入庫中的文件夾,然後克里特島一個助手名mail_helper.php功能把這段代碼這樣

function sendmail($email, $subject = FALSE, $message = FALSE, $headers = FALSE, $from = FROM_EMAIL) { 

    $mail = new PHPMailer(); 

    $mail->IsSMTP(); // we are going to use SMTP 
    $mail->SMTPAuth = true; // enabled SMTP authentication 
    $mail->SMTPSecure = "ssl"; // prefix for secure protocol to connect to the server 
    $mail->Host = SMTP_HOST;  // setting GMail as our SMTP server 
    $mail->Port = SMTP_PORT;     // SMTP port to connect to GMail 
    $mail->Username = SMTP_USERNAME; // user email address 
    $mail->Password = SMTP_PASSWORD;   // password in GMail 
    if ($from != FALSE) 
     $mail->SetFrom($from, FROM_EMAIL); //Who is sending the email 

// $mail->AddReplyTo("[email protected]","Firstname Lastname"); //email address that receives the response 
    if ($subject != FALSE) { 
     $mail->Subject = $subject; 
    } 
    if ($message != FALSE) { 
     $mail->Body = $message; 
     $mail->AltBody = $message; 
    } 

    if (is_array($email) && count($email) > 0) { 
     for ($i = 0; $i < count($email); $i++) { 
      $destino = $email[$i]; // Who is addressed the email to 

      $mail->AddAddress($destino, $destino); 
     } 
    } else { 
     $destino = $email; // Who is addressed the email to 
     $mail->AddAddress($destino, $destino); 
    } 

    // $mail->AddAttachment("images/phpmailer.gif");  // some attached files 
    // $mail->AddAttachment("images/phpmailer_mini.gif"); // as many as you want 
    if (!$mail->Send()) { 
     return FALSE; 
    } else { 
     return TRUE; 
    } 
} 

並加載助手,並使用這個助手這樣

sendmail("[email protected]","Test Subject", "This is test", $headers = FALSE, FROM_EMAIL) 
+0

是否可以在代碼點火器中使用PHPMailer ..?如果是這樣,我應該把PHPMailer放在CI 3.0裏面? – Keynes

+0

是的,它是可能的,簡單。從上面的鏈接下載phpmailer並將文件夾放在庫文件夾中,並創建一個像上面的幫手,我給了一個代碼。 –

+0

你能否詳細解釋一下,如何放入庫文件夾並創建幫助文件。你能一步一步幫我嗎?? – Keynes