2017-11-24 2 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; 
    } 
} 

} 메시지를 전송하는 동안 암이 오류가

내 서버가이 오류가 발생하고 작동하지 않습니다 구성되어 있지만 메일은 내 사이트에서 전송되지 않습니다. 어떻게 구성 할 수 있습니까? 구성 섹션에서 메일을 보내기위한 비밀번호와 사용자 이름을 제공해야합니까? 어떻게 도와 드릴까요? ( 주소와 이메일 구성에서 주소가 혼동을 느낍니다. (

+0

메시지를 보내는 동안 어떤 오류가 있었습니까? 이 오류를 우리와 공유 할 수 있습니까? –

답변

0

다른 여러 제공자를 통해 이메일을 보내는 것은 항상 힘든 작업입니다.

어쩌면 확인이 비록

,

$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

네, 여기에 붙여 넣지 마세요 :) –