简体   繁体   中英

Making Http request to Server to email - Android

I'm making an android application. My application has a quiz. When the user passes the quiz they are emailed a certificate. I am doing this by making a http request to a server and the email is sent through php. I got it to work with just the email body but I also want the user to be able to enter their email address (in the application) and the php file should get this from the code.

Here is my code when I just had the email body (which worked) and sent it to myself

new HttpPosting().execute("http://saf=fo.com/brEmail.php?emailBody="+ "HeyYOUUUUU");

Here is what I tried to add the email recipient (doesn't work)

new HttpPosting().execute("http://sainfo.com/bredanSendEmail.php?emailBody="
                        + "HeyYOUUUUU"+"?emailTo="+"brendan@hotmail.com");

here is the php file on the server:

<?php

$body = $_GET['emailBody'];
$headers = 'From: IFA Safeguarding App <welfare@irishfa.com>';
$to = $_GET['emailTo'];

$subject = "Email from IFA Safeguarding in Football App";
if (mail($to, $subject, $body, $headers)) {
    echo "1";
} else {
    echo "0";
}

?>

Any help is much appreciated

Change your URL to:

new HttpPosting().execute("http://safeandsecureinfo.com/brendanSendEmail.php?emailBody="
                        + "HeyYOUUUUU"+"&emailTo="+"brendan@hotmail.com");

NOTE:

Please note that the php code is very insecure as the php file can be accessed by anyone, meaning a spammer can send thousands of emails from your server, to anyone they choose

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM