如何调用php文件发送邮件? ,Android
发布时间:2020-12-13 17:18:39 所属栏目:PHP教程 来源:网络整理
导读:我有以下mail.php文件: ?php$name = $_POST['name'];$to = $_POST['to'];$from = $_POST['from'];$subject = $_POST['subject'];$message = "From: ".$name."rn";$message .= $_POST['message'];$headers = "From:" . $from;mail($to,$subject,$message,$
我有以下mail.php文件:
<?php $name = $_POST['name']; $to = $_POST['to']; $from = $_POST['from']; $subject = $_POST['subject']; $message = "From: ".$name."rn"; $message .= $_POST['message']; $headers = "From:" . $from; mail($to,$subject,$message,$headers); ?> 我有以下布局从我的应用程序发送邮件: 我想在点击发送按钮后发送邮件到静态邮件,例如:mymail@mail.com. 解决方法
这里是:
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(); } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |