我正在构建一个应用程序,该应用程序中要发送的任务之一就是向用户发送电子邮件,
这是我的php代码
where
这是我的页面联系人。
<?php
require_once __DIR__ . '/connect.php';
require 'phpmailer/PHPMailerAutoload.php';
$response = array();
$_POST['fristName']=" null";
$_POST['lastName']=" null";
$_POST['email']=" null";
$_POST['phoneNumber']=" null";
if($_POST['fristName']&&$_POST['email']&&$_POST['phoneNumber']){
$mail = new PHPMailer;
$mail->setFrom($_POST['email'], $_POST['fristName'].' '.$_POST['lastName']." - Application mobile");
$mail->addAddress('exemple.xx@xxxxx.com', 'Mobile Android');
$mail->Subject = 'Email from : '.$_POST['email'];
$message = utf8_encode(htmlentities("hi dear", ENT_QUOTES, "UTF-8"));
$message .="<p>".utf8_encode(htmlentities($_POST['fristName'], ENT_QUOTES, "UTF-8"))."</p>"
$message .="<p>".utf8_encode(htmlentities($_POST['lastName'], ENT_QUOTES, "UTF-8"))."</p>"
$message .="<p>".utf8_encode(htmlentities($_POST['email'], ENT_QUOTES, "UTF-8"))."</p>"
$message .="<p>".utf8_encode(htmlentities($_POST['phoneNumber'], ENT_QUOTES, "UTF-8"))."</p>"
$message .="<br/><br/>Cordialement,";
$mail->Body = $message;
$mail->IsHTML(true);
if(!$mail->send()) {
$response["success"] = 0;
$response["message"] = "Email not sent";
} else {
$response["success"] = 1;
$response["message"] = "succes";
}
}
我成功发送了电子邮件,但所有人 场什么都不给我
我不知道我在做什么错
答案 0 :(得分:0)
您的PHP脚本是从Ionic应用程序接收数据吗,我认为您的发布请求未随PHP脚本的请求一起发送任何数据接受表单数据,因此您需要像这样添加Ionic应用程序数据
send(){
var headers = new Headers();
headers.append("Accept", "application/json");
let options = new RequestOptions({ headers: headers });
let body = new FormData();
body.set("fristName",this.fristName);
body.set('lastName', this.lastName);
body.set("phoneNumber", this.phoneNumber);
body.set("email", this.email);
return this.http
.post("http://www.android.transatour.ma/contact_script.php", body, options)
.map(res => res.json());
}
尝试一下。