gpt4 book ai didi

android - 如何调用php文件发送邮件?? , 安卓

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:52:17 25 4
gpt4 key购买 nike

我有以下 mail.php 文件:

<?php
$name = $_POST['name'];
$to = $_POST['to'];
$from = $_POST['from'];
$subject = $_POST['subject'];
$message = "From: ".$name."\r\n";
$message .= $_POST['message'];
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
?>

我有以下布局来从我的应用程序发送邮件: enter image description here

我想在点击发送按钮后将邮件发送到静态邮件,例如:mymail@mail.com。
如何通过调用上面的 php 文件来发送邮件。
我听说过调用上面的 php 文件的 post 方法但对此一无所知。
请帮忙!

最佳答案

这里是:

    public static void sendData(String name, String to, String from, String subject, String message)
{
String content = "";

try
{
/* Sends data through a HTTP POST request */
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("http://your.website.com");
List <NameValuePair> params = new ArrayList <NameValuePair>();
params.add(new BasicNameValuePair("name", name));
params.add(new BasicNameValuePair("to", to));
params.add(new BasicNameValuePair("from", from));
params.add(new BasicNameValuePair("subject", subject));
params.add(new BasicNameValuePair("message", message));
httpPost.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));

/* Reads the server response */
HttpResponse response = httpClient.execute(httpPost);
InputStream in = response.getEntity().getContent();

StringBuffer sb = new StringBuffer();
int chr;
while ((chr = in.read()) != -1)
{
sb.append((char) chr);
}
content = sb.toString();
in.close();

/* If there is a response, display it */
if (!content.equals(""))
{
Log.i("HTTP Response", content);
}
}
catch (Exception e)
{
e.printStackTrace();
}
}

关于android - 如何调用php文件发送邮件?? , 安卓,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9924760/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com