2017-04-09 48 views
2

我需要使用API​​函數來發送郵件與插入的數據管理員發送郵件, 功能是看起來像使用API​​數據笨

public function requestbookingresort_post() 
    { 
     $languageid = $this->input->post('languageId'); 
     $resort_id = $this->input->post('resortId'); 
     $booking_from = $this->input->post('bookingFrom'); 
     $booking_to = $this->input->post('bookingTo'); 
     $contact_name = $this->input->post('contactName'); 
     $contact_email = $this->input->post('contactEmail'); 
     $contact_phone = $this->input->post('contactPhone'); 
     $userid = $this->input->post('userId'); 

     if (empty($languageid)) 
     { 
      $languageRecord = getDefaultlanguage(); 
      $languageid = $languageRecord->languageid; 
     } 
     $language_file = languagefilebyid($languageid); 
     $this->lang->load($language_file, $language_file); 

     if (empty($resort_id) || empty($booking_from) || empty($booking_to) || empty($contact_name) || empty($contact_email) || empty($contact_phone)) 
     { 
      $arr['status'] = 'error'; 
      $arr['statusMessage'] = lang('error_in_booking'); 
      $arr['data'] = array(); 
     } 
     else 
     { 
      $dataArray = array(
       "languageid" => $languageid, 
       "userid" => empty($userid) ? "0" : $userid, 
       "resortid" => $resort_id, 
       "bookingfrom" => date("Y-m-d", strtotime($booking_from)), 
       "bookingto" => date("Y-m-d", strtotime($booking_to)), 
       "contactname" => $contact_name, 
       "contactemail" => $contact_email, 
       "contactphone" => $contact_phone, 
       "requestdatetime" => date("Y-m-d H:i:s"), 
      ); 
      $this->load->model("Resort_model"); 
      $booking_id = $this->Resort_model->saveBookingRequest($dataArray); 

      if (empty($booking_id)) 
      { 
       $arr['status'] = 'error'; 
       $arr['statusMessage'] = lang('error_occurred'); 
       $arr['data'] = array(); 
      } 
      else 
      { 

       $arr['status'] = 'success'; 
       $arr['statusMessage'] = lang('booking_request_submit'); 
       $arr['data'] = array(); 
      } 
     } 

     $response = array(
      "response" => $arr 
     ); 

     $this->set_response($response, REST_Controller::HTTP_CREATED); // CREATED (201) being the HTTP response code 
    } 

但我在笨新和沒」不知道如何從數據庫中獲取這些傳遞的數據,以便將郵件發送到管理員郵件或其他東西?

回答

0

試試這個。

public function requestbookingresort_post() 
{ 
    // Your operations 
    $response = array(
     "response" => $arr 
); 
    $this->sendMail($response) 
    $this->set_response($response, REST_Controller::HTTP_CREATED); // CREATED (201) being the HTTP response code 
} 
public function sendMail($response) 
{ 
    $settings=$this->Some_model->getEmailSettings(); 
    $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  = $settings->host;     // setting GMail as our SMTP server 
    $mail->Port  = $settings->port;     // SMTP port to connect to GMail 
    $mail->Username = $settings->email;     // user email address 
    $mail->Password = $settings->password;    // password in GMail 
    $mail->SetFrom($settings->sent_email, $settings->sent_title);  //Who is sending the email 
    $mail->AddReplyTo($settings->reply_email,$settings->reply_email); //email address that receives the response 
    $mail->Subject = "Your Booking has been confirmed"; 
    $mail->IsHTML(true); 
    $body = $this->load->view('path/email_template', $response, true); 
    $mail->MsgHTML($body); 
    $destination = $response['contactEmail']; // Who is addressed the email to 
    $mail->AddAddress($destination); 
    if(!$mail->Send()) { 
     $data['code']=300; 
     $data["message"] = "Error: " . $mail->ErrorInfo; 
    } 
} 

確保你在你的庫PHPMailer和正在加載的庫在你的構造,我希望你保持電子郵件設置在你的數據庫。如果沒有,你可以手動提供主機,端口,用戶名和密碼字段

+0

你能告訴我哪一行來自: $ body = $ this-> load-> view('path/email_template',$ response,true ); –

+0

噢,如果你使用的是這行,用來加載你的HTML郵件模板。它更容易加載視圖,而不是創建一個這裏 –

+0

我想我需要上傳作曲者「phpmailer/phpmailer」:「〜5.2」? 或者它不會和我一起工作的權利? –