2016-06-30 25 views
0

私はphp codeigniterプロジェクトに取り組んでいます。ローカルホストから電子メールを送信したいと思います。phpでlocalhostから電子メールを送信する方法CodeIgniter

以下は私のコントローラの機能です。

 $config = Array(
       'protocol' => 'smtp', 
       'smtp_host' => 'ssl://smtp.google.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]"); 
    $this->email->to("[email protected]"); 
    $this->email->subject("Email with Codeigniter"); 
    $this->email->message("This is email has been sent with Codeigniter"); 

    if($this->email->send()) 
    { 
     echo "Your email was sent.!"; 
    } else { 
     show_error($this->email->print_debugger()); 
    } 

私はphp.iniの 'extension = php_openssl.dll'拡張機能を有効にしていることに注意してください。私のphp.iniファイルはC:/ AppServ/php5にあります。コードを実行すると、ページにエラーが発生します。

The following SMTP error was encountered: 1923818231 Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP? Unable to send data: AUTH LOGIN Failed to send AUTH LOGIN command. Error: Unable to send data: MAIL FROM:

Severity: Warning

Message: date(): It is not safe to rely on the system's timezone settings. You are required to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone.

Filename: libraries/Email.php

Line Number: 705

+0

あなたは 'アクティブでしたあなたはこのようにそれを使用することができますPHPのphp_openssl拡張子? 'php.ini'を編集してそれを有効にし、'# 'コメントを削除します – RiggsFolly

+0

php.iniで 'extension = php_openssl.dll'拡張を有効にしました。私のphp.iniファイルは、C:/ AppServ/php5とC:/ AppServ/php7フォルダにあります。 –

+0

ウェブサーバで使用される可能性が高い 'wherever \ apache \ bin'のものはどうですか? – RiggsFolly

答えて

1

使用phpmailerの:

これらはエラーです。そのPHPMailerをご利用いただけます。代わりにこれを試して、あなたの$configアレイでは

public function send_mail() 
    { 
     require_once(APPPATH.'third_party/PHPMailer-master/PHPMailerAutoload.php'); 
     $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.gmail.com";  // setting GMail as our SMTP server 
     $mail->Port  = 465;     // SMTP port to connect to GMail 
     $mail->Username = "[email protected]"; // user email address 
     $mail->Password = "password";   // password in GMail 
     $mail->SetFrom('[email protected]', 'Mail'); //Who is sending 
     $mail->isHTML(true); 
     $mail->Subject = "Mail Subject"; 
     $mail->Body  = ' 
      <html> 
      <head> 
       <title>Title</title> 
      </head> 
      <body> 
      <h3>Heading</h3> 
      <p>Message Body</p><br> 
      <p>With Regards</p> 
      <p>Your Name</p> 
      </body> 
      </html> 
     '; 
     $destino = [email protected]; // Who is addressed the email to 
     $mail->AddAddress($destino, "Receiver"); 
     if(!$mail->Send()) { 
      return false; 
     } else { 
      return true; 
     } 
    } 

は、Gmailアカウントに信頼性の低いアプリケーションへのアクセスを設定することを忘れないでください

+0

に役立つかもしれませんが、質問に答えるには....あなたがphp.iniファイルで 'php_openssl'拡張を有効にしていることを確認してください。 PHP – RiggsFolly

2

'smtp_host' => 'ssl://smtp.googlemail.com', 
関連する問題