2017-09-12 8 views
-1

コードが受信者に電子メールを送信していません........................... .........コードイグナイタと電子メールを使用してメールを送信しようとしています

class Welcome extends Frontend_Controller { 
public function __construct() { 
    parent::__construct(); 
public function Subscribe_Mail() { 
    $this->_Creating_subscription_mail(); 
    if ($this->form_validation->run() === TRUE) { 
    $email = $this->input->post('email'); 
    $to_email = "[email protected]"; 
    $from_email = trim($email); 
    $config['useragent'] = "CodeIgniter"; 
    $config['protocol'] = "Send mail"; 
    $config['SMTPSecure'] = 'ssl'; 
    $config['smtp_host'] = 'mail.XXX.com'; 
    $config['smtp_user'] = 'rrrrr'; 
    $config['smtp_pass'] = 'xxxxxxxxxxxxxxxxxxx'; 
    $config['mailpath'] = '/usr/bin/sendemail'; 
    $config['smtp_port'] = '587'; 
    $config['smtp_timeout'] = '5'; 
    $config['charset'] = 'iso-8859-1'; 
    $config['wordwrap'] = TRUE; 
    $config['crlf'] = "\r\n"; 
    $config['newline'] = "\r\n"; 
    $config['mailtype'] = 'html'; 
    $config['validation'] = TRUE; 
    $config['web_admin_email_id'] = '[email protected]'; 
    $this->load->library('email'); 
    $this->email->initialize($config);  
    $data = array(); 
    $data['email'] = $email; 
     $this->email->from('[email protected]', 'Servhigh'); 
     $this->email->to('$to_email'); 
     $this->email->subject('Request Email On Servhigh.com'); 
     $this->email->message('This is my message'); 
     $this->email->send();  

コントローラでこのコードが間違っていることを知りたいと思います。

答えて

0

最初のチェック、最後にこれを追加することで送信したりしないようにしようとしている場合:

if(!$this->email->send()){ 
    echo "Failed to send mail": 
} else { 
    echo "Working... Mail Send"; 
} 

そして、これに置き換えます。これに

$this->email->to('$to_email'); 

$this->email->to($to_email); 
+1

私はそれを追加しましたが、送信していません... –

1
$this->email->to('$to_email'); 

これを

01に修正してください
$this->email->to($to_email); 

例:

$data ="hai"; 
echo "$data"; // output:hai 
echo '$data'; // output:$data 
echo $data; //output:hai 

$config['mailpath'] = '/usr/bin/sendemail'; 

$config['mailpath'] = "/usr/bin/sendmail"; 

使用を交換して、このその私のために働い

function send_mail() 
{ 
    $this->load->library('email'); 
    $config = array(); 
    $config['useragent'] = "CodeIgniter"; 
    $config['mailpath'] = "/usr/bin/sendmail"; 
    $config['protocol'] = "smtp"; 
    $config['smtp_host'] = "smtp.sendgrid.net"; 
    $config['smtp_user'] = "your_user_name"; 
    $config['smtp_pass'] = "your_password";   
    $config['smtp_port'] = "25"; 
    $config['mailtype'] = 'html'; 
    $config['charset'] = 'utf-8'; 
    $config['newline'] = "\r\n"; 
    $config['wordwrap'] = TRUE; 
    $this->load->library('email'); 
    $this->email->initialize($config);   
    $this->email->subject('TEST SUBJECT'); 
    $this->email->message("THIS IS A TEST MESSAGE"); 
    $this->email->from("yourmailid" );   
    $this->email->to("yourmailid"); 
    if($this->email->send()) 
    { 
    echo "success"; 
    } 
    else 
    { 
    echo $this->email->print_debugger(); 
    } 
} 
+0

print_debuggerにメールを送信するかどうかを確認してください。 echo $ this-> email-> print_debugger(); – karthikeyan

+0

まだ動作していません –

+0

まだ動作していません@ karthikeyan –

0

あなたの要件に応じて資格情報を変更してください(下記のコードを試してみてください):

class Welcome extends CI_Controller { 

    public function __construct() { 
     parent::__construct(); 
    } 

    public function subscribe_mail() { 
     $config['smtp_host'] = 'mail.xxx.com'; 
     $config['smtp_user'] = 'rrrrr'; 
     $config['smtp_pass'] = 'xxxxxxxxxxxxxxxxxxx'; 
     $config['charset'] = 'iso-8859-1'; 
     $config['crlf'] = "\r\n"; 
     $config['newline'] = "\r\n"; 
     $config['mailtype'] = 'html'; 
     $config['validate'] = TRUE; 
     $this->load->library('email'); 
     $this->email->initialize($config);  
     $this->email->from('[email protected]', 'Your Name'); 
     $this->email->to('[email protected]'); 
     $this->email->subject('Request Email On Servhigh.com'); 
     $this->email->message($this->input->post('email')); 
     if($this->email->send()) { 
      echo "success"; 
     } 
     else { 
      echo $this->email->print_debugger(); 
     } 
    } 
} 

まず、メソッドの名前をSubscribe_Mail()からsubscribe_mail()に変更しました。

第2に、定義済みの検証ルールが見つからないため、if ($this->form_validation->run() === TRUE) {を削除しました。 manualから

あなたはまだ何も を検証するためにフォーム検証クラスに語っていないので、それはデフォルトではFALSE(ブール偽)を返します。 run()メソッド は、 のいずれも失敗していないルールを正常に適用した場合にのみTRUEを返します。基本的に存在する場合ない検証ルールが定義されていないと検証が成功しない場合、run()方法は、常に、それによって実行されることifステートメントの内部コードを防止する、FALSE返すことを意味

第3に、不要な設定(既定では既に指定された値を持つ)を削除しました。

第4に、Frontend_ControllerCI_Controllerに変更し、$this->_Creating_subscription_mail();を削除しました。

第5に、{}の問題を修正しました。

注:便宜上、検証部分を削除しましたが、実際の実装では処理前にデータの検証を行う必要があります。

+0

申し訳ありませんが、私は厳しい週があったので、フォローアップできませんでした。私はコードをいくつか修正しました。それでも解決策が見つからない場合は、コードを試してみてください。 – Raja

関連する問題