使用codeigniter使用api数据发送邮件

时间:2017-04-09 10:20:05

标签: php codeigniter api email

我需要使用APi函数向管理员发送带有插入数据的邮件, 功能看起来像那样

find . -type f -name '*.png' | while read FILE ; do
    newfile="$(echo ${FILE} |sed -e 's/-/_/g')";
    mv "${FILE}" "${newfile}" ;
done

但我是codeigniter的新手,并且不知道如何从数据库中获取此传递数据以将邮件发送到管理邮件或其他什么内容?

1 个答案:

答案 0 :(得分: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,并且您正在构建器中加载库,我希望您在数据库中保留电子邮件设置。如果没有,您可以手动提供主机,端口,用户名和密码字段