2017-04-09 2 views
2

ich Mail an den Administrator mit den eingefügten Daten mit API-Funktion, die Funktion senden muß, ist aussehen wie dieSenden Mail mit api Daten mit codeigniter

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 
    } 

Aber ich bin neu bei codeigniter und didn‘ Wissen Sie, wie Sie diese übergebenen Daten von der Datenbank erhalten, um damit E-Mails an die Admin-Mail zu senden?

Antwort

0

Versuchen Sie es.

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; 
    } 
} 

Stellen Sie sicher, PHPMailer in Ihren Bibliotheken haben und Sie die Bibliothek in Ihrem Konstruktor Laden und ich hoffe, Sie halten E-Mail-Einstellungen in Ihrer Datenbank. Wenn nicht, können Sie die Felder Host, Port, Benutzername und Passwort manuell eingeben

+0

Können Sie mir sagen, woher die Zeile kommt: $ body = $ this-> load-> view ('Pfad/Email_Template', $ Response, True); –

+0

oh diese Zeile wird verwendet, um Ihre HTML-E-Mail-Vorlage zu laden, wenn Sie eine verwenden. es ist viel einfacher, eine Ansicht zu laden, anstatt eine hier zu erstellen –

+0

Ich denke, ich muss Compiler für "phpmailer/phpmailer" hochladen: "~ 5.2"? Oder es wird nicht mit mir richtig funktionieren? –

Verwandte Themen