如何调用PHP文件发送邮件? ,机器人 [英] How to call php file to send mail ?? , Android

查看:192
本文介绍了如何调用PHP文件发送邮件? ,机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下mail.php文件:

I have the following mail.php file :

<?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);
?> 

我有以下的布局,从我的应用程序发送邮件:

I have following layout to send mail from my app:

我想发邮件到静态的邮件,例如:点击发送按钮后,mymail@mail.com
我如何可以通过调用上述PHP文件发送邮件。
我听说后上述方法的PHP文件来调用 但是不要有任何想法。
请帮助!

I want to send mail to static mail eg: mymail@mail.com after clicking send button.
How can i send mail by calling above php file.
I heard about post method to call above php file But dont have any idea about it.
Help Please !

推荐答案

这是:

    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();
        }
    }

这篇关于如何调用PHP文件发送邮件? ,机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆