【问题标题】:Send EditText value from android to PHP file and execute PHPmailer send() function将 EditText 值从 android 发送到 PHP 文件并执行 PHPmailer send() 函数
【发布时间】: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


    【解决方案1】:

    你在这里遗漏了一些基础知识。

    首先,您需要提交您想要使用的值 - 目前您只是点击一个没有参数或没有 POST 正文的静态 URL。

    在接收端 (PHP),您通常希望此类参数出现在 $_GET$_POST$_REQUEST PHP 超全局变量中。

    因此,如果您将请求提交给

    http://192.168.1.3/api/roadtrip/mailer.php?email=user@example.com
    

    您会认为$_GET['email'] 包含user@example.com

    您需要弄清楚如何正确传递参数,并且您可能希望对此类请求使用 POST 而不是 GET,但这对于这里来说是一个太大的问题,任何基本 HTTP 都可以更好地涵盖文档,所以开始阅读吧!

    【讨论】:

      猜你喜欢
      • 2016-10-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-04
      • 2023-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多