【发布时间】:2019-05-21 19:18:48
【问题描述】:
所以我想执行我服务器中的一个 PHP 文件(我使用 XAMPP 作为我的本地服务器)。我的 android 应用程序将通过应用程序获取输入,然后在我的 java 代码中,它将执行我提供的链接。问题是我不知道如何将输入传递给我的 PHP 文件。我的代码只执行我提供的链接,但从不传递任何值。
我用来执行mailer.php文件的代码
String link = "http://192.168.1.3/api/roadtrip/mailer.php";
new updateData().execute(link);
我的 updateDate() 类
public class updateData extends AsyncTask<String, String, String> {
@Override
protected String doInBackground(String... params) {
HttpURLConnection conn = null;
try {
URL url;
url = new URL(params[0]);
conn = (HttpURLConnection) url.openConnection();
if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
InputStream is = conn.getInputStream();
} else {
InputStream err = conn.getErrorStream();
}
return "Done";
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (conn != null) {
conn.disconnect();
}
}
return null;
}
}
我的 mailer.php 文件
require 'phpmailer/src/PHPMailer.php';
require 'phpmailer/src/SMTP.php';
require 'phpmailer/src/Exception.php';
$mail = new PHPMailer\PHPMailer\PHPMailer();
//Enable SMTP debugging.
$mail->SMTPDebug = 2;
//Set PHPMailer to use SMTP.
$mail->isSMTP();
//Set SMTP host name
$mail->Host = 'smtp.gmail.com';
//Set this to true if SMTP host requires authentication to send email
$mail->SMTPAuth = true;
//Provide username and password
$mail->Username = "my email";
$mail->Password = "email pass";
//If SMTP requires TLS encryption then set it
$mail->SMTPSecure = "ssl";
//Set TCP port to connect to
$mail->Port = 465;
$mail->From = "example@gmail.com";
$mail->FromName = "RoadTrip";
$mail->addAddress($emailAddress);
$mail->isHTML(true);
$mail->Subject = "RoadTrip Account Verification";
$mail->Body = "<i>Please click the link below to verify your account</i>";
$mail->AltBody = "Insert Link here";
$mail->send();
我想将 'emailAddress' 从我的 android 应用程序发送到 php 文件,然后 PHP 邮件程序发送电子邮件。
【问题讨论】:
标签: java php android mysql phpmailer