2017-11-24 7 views
0

マイビュー私のメールは私のお問い合わせページ

<div class="col-sm-6"> 
    <div class="single_contant_left padding-top-90 padding-bottom-90"> 
    <?php $attributes = array("class" => "form-horizontal", "name" => "contactform"); 
      echo form_open("contactform/contactus", $attributes);?> 
    <div id="formid"> 
     <div class="col-lg-8 col-md-8 col-sm-10 col-lg-offset-2 col-md-offset-2 col-sm-offset-1"> 

     <div class="row"> 
      <div class="col-sm-12"> 
      <div class="form-group"> 
       <input type="text" class="form-control" name="name" value="<?php echo set_value('name'); ?>" placeholder="First Name" required> 
       <span class="text-danger"><?php echo form_error('name'); ?></span> 
      </div> 
      </div> 
     </div> 


     <div class="row"> 
      <div class="col-sm-12"> 
      <div class="form-group"> 
       <input type="email" class="form-control" name="email" placeholder="Email" value="<?php echo set_value('email'); ?>" required> 
       <span class="text-danger"><?php echo form_error('email'); ?></span> 
      </div> 
      </div> 
      <div class="col-sm-12"> 
      <div class="form-group"> 
       <input type="text" class="form-control" name="subject" placeholder="Subject" value="<?php echo set_value('subject'); ?>" required> 
       <span class="text-danger"><?php echo form_error('subject'); ?></span> 
      </div> 
      </div> 
     </div> 


     <div class="form-group"> 
      <textarea class="form-control" name="message" rows="7" placeholder="Message"><?php echo set_value('message'); ?></textarea> 
      <span class="text-danger"><?php echo form_error('message'); ?></span> 
     </div> 

     <div class=""> 
      <input type="submit" name="submit" value="SEND MESSAGE" class="btn btn-lg"> 
     </div> 
     </div> 
     <?php echo form_close(); ?> 
     <?php echo $this->session->flashdata('msg'); ?> 
    </div> 
    </div> 

</div> 

私のコントローラ

<?php 




class Contactform extends CI_Controller 
    { 
     public function __construct() 
     { 
      parent::__construct(); 
     $this->load->helper(array('form','url')); 
     $this->load->library(array('session', 'form_validation', 'email')); 
} 

function contactus() 
{ 
    //set validation rules 
    $this->form_validation->set_rules('name', 'Name', 'required'); 
    $this->form_validation->set_rules('email', 'Emaid ID', 'trim|required|valid_email'); 
    $this->form_validation->set_rules('subject', 'Subject', 'trim|required'); 
    $this->form_validation->set_rules('message', 'Message', 'trim|required'); 

    //run validation on form input 
    if ($this->form_validation->run() == FALSE) 
    { 
     //validation fails 
     $this->load->view('header_vw'); 
     $this->load->view('center_vw'); 
     $this->load->view('footer_vw'); 
    } 
    else 
    { 
     //get the form data 
     $name = $this->input->post('name'); 
     $from_email = $this->input->post('email'); 
     $subject = $this->input->post('subject'); 
     $message = $this->input->post('message'); 

     //set to_email id to which you want to receive mails 
     $to_email = '[email protected]'; 

     //configure email settings 
     $config['protocol'] = 'smtp'; 
     $config['smtp_host'] = 'ssl://smtp.gmail.com'; 
     $config['smtp_port'] = '465'; 
     $config['smtp_user'] = '[email protected]'; 
     $config['smtp_pass'] = '[email protected]'; 
     $config['mailtype'] = 'html'; 
     $config['charset'] = 'iso-8859-1'; 
     $config['wordwrap'] = TRUE; 
     $config['newline'] = "\r\n"; //use double quotes 
     $this->load->library('email', $config); 
     $this->email->initialize($config);       

     //send mail 
     $this->email->from($from_email, $name); 
     $this->email->to($to_email); 
     $this->email->subject($subject); 
     $this->email->message($message); 
     if ($this->email->send()) 
     { 
      // mail sent 
      $this->session->set_flashdata('msg','<div class="alert alert-success text-center">Your mail has been sent successfully!</div>'); 
      redirect('contactform/contactus'); 
     } 
     else 
     { 
      //error 
      $this->session->set_flashdata('msg','<div class="alert alert-danger text-center">There is error in sending mail! Please try again later</div>'); 
      redirect('contactform/contactus'); 
     } 
    } 
} 

//custom validation function to accept only alphabets and space input 
function alpha_space_only($str) 
{ 
    if (!preg_match("/^[a-zA-Z ]+$/",$str)) 
    { 
     $this->form_validation->set_message('alpha_space_only', 'The %s field must contain only alphabets and space'); 
     return FALSE; 
    } 
    else 
    { 
     return TRUE; 
    } 
} 

}

私のサーバーは、メッセージを送信中にAmはエラーを取得中にエラーを取得しています動作しません設定されているが、メールは私のサイトから送信されていません。どのように設定すれば、設定セクションでメールを送信するためのパスワードとユーザ名を与えたいですか?どのように助けてくださいを構成することができます:( アドレスと電子メール構成のアドレスから(

+0

メッセージの送信中に、どのエラーが発生しましたか?このエラーを私たちと共有できますか? –

答えて

0

私はこれを数回行っていますが、別のプロバイダを介して電子メールを送信することは常に痛い仕事です。この多分OK、

$config['newline'] = "\r\n"; //use double quotes 

ものの

しかし、Sending email with gmail smtp with codeigniter email library

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

ことを示唆している。また、あなたがGmailで安全性の低いアプリケーションを許可しますが、確かではありますか?

+0

$ config ['smtp_user'] = '.... @ gmail.com'にユーザ名とパスワードを入力しますか? $ config ['smtp_pass'] = 'als .... @ ......'; – Alshoja

+0

ええ、そこに貼り付ける必要はありません:) –

関連する問題