dsc862009
2014-09-19 11:04 阅读 65

向服务器发送Http请求以发送电子邮件 - 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

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    dsbgltg159136540 dsbgltg159136540 2014-09-19 11:12

    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

    点赞 评论 复制链接分享

相关推荐