我有一个post函数,可以在数据库中插入有关进程的信息,并向一个收件人发送电子邮件。
$app->post('/sendemail', function ($request, $response) {
//Save info process
$message = saveDataBaseInfo();
if ($message == "OK") {
// Send email
$res = sendEmail("Some text", "<p>Some text</p>", "Some subject", "email@email.com");
if ($res == "Fail") {
return $res;
}
}
});
public function sendEmail($body, $bodyHtml, $subject, $emailTo) {
$mail = new PHPMailer;
$mail->SingleTo = true;
$mail->isSMTP();
$mail->Host = 'myHost';
$mail->SMTPAuth = true;
$mail->Username = 'theuser';
$mail->Password = '******';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->setFrom("emailfrom@emailfrom.com", "", false);
$mail->addAddress($emailTo);
$mail->isHTML(true);
$mail->Subject = $subject;
$mail->Body = $bodyHtml;
$mail->AltBody = $body;
$send = $mail->send();
if (!$send) {
return "Success"
} else {
return "Fail";
}
}
我在我的Android应用上调用此功能,如下面的代码
// Click event function
private void sendEmailClick() {
HashMap<String, String> parms = new HashMap<>();
// parms like emailTo for example
TaskServerAsync taskServerAsync = new TaskServerAsync(this, parms);
taskServerAsync.execute(R.string.urlSendEmail);
}
public class TaskServerAsync extends AsyncTask<Integer, String, JSONObject> implements Response.ErrorListener {
private Map<String, String> parm;
private Context context;
public TaskServerAsync(Context context ,Map<String, String> parms) {
this.parm = parm;
this.context = context;
}
@Override
protected void onPreExecute() {
//Show progressBar
progressBar.show();
}
@Override
protected JSONObject doInBackground(Integer... values) {
RequestFuture<JSONObject> future = RequestFuture.newFuture();
// Class send request server with volley
ServerConn.send(context, values[0], parms, future, this);
JSONObject json = null;
try {
// Get future response
json = future.get(10, TimeUnit.SECONDS);
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
} catch (TimeoutException e) {
e.printStackTrace();
}
return json;
}
@Override
protected void onProgressUpdate(String... values) {
}
@Override
protected void onPostExecute(JSONObject response) {
dismissProgressBar();
}
@Override
public void onErrorResponse(VolleyError error) {
// Show error server and dismiss ProgressBar
dismissProgressBar();
}
private void dismissProgressBar() {
if (progressBar != null)
progressBar.dismiss();
}
}
但是帖子功能被解雇了两次。怎么了?我需要在apache上配置一些东西吗?有人可以帮助我吗?