I have the following function in my Android app:
void sendEmail(String PHPfileUurl, String receiverEmail, String fromEmail) {
        ParseUser currentUser = ParseUser.getCurrentUser();
        StringBuilder messageBuilder = new StringBuilder();
        for (int i=0; i<productsOrdered.size(); i++){
            messageBuilder.append(productsOrdered.get(i)).append("\n");
        }
        String mess = messageBuilder.toString();
        String parameters = "name=" + currentUser.getString(Configurations.USER_FULLNAME) +
                "&fromEmail=" + fromEmail +
                "&receiverEmail=" + receiverEmail +
                "&messageBody=" + mess +
                "&storeName=" + Configurations.MERCHANT_NAME +
                "&shippingAddress=" + currentUser.getString(Configurations.USER_SHIPPING_ADDRESS);
        String strURL = PHPfileUurl + parameters;
        strURL = strURL.replace(" ", "%20");
        strURL = strURL.replace("\n", "%20");
        Log.i(Configurations.TAG, "PHP STRING URL: " + strURL);
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);
        try {
            URL url;
            url = new URL(strURL);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("POST");
            conn.setConnectTimeout(20000);
            conn.setReadTimeout(20000);
            conn.setDoInput(true);
            conn.setDoOutput(true);
            if( conn.getResponseCode() == HttpURLConnection.HTTP_OK ){
                InputStream is = conn.getInputStream();
                Log.i(Configurations.TAG, "EMAIL RESPONSE: " + conn.getResponseMessage());
            } else {
                InputStream err = conn.getErrorStream();
                Log.i(Configurations.TAG, "ERROR ON EMAIL: " + err);
            }
        } catch (IOException e) {e.printStackTrace(); }
    }
When I call that function the Logcat prints out this message:
I/log-: PHP STRING URL: http://example.com/myapp/email-admin.php?name=Mark%20Doe&fromEmail=myemail@gmail.com&receiverEmail=admin@mydomain.com&messageBody=PRODUCT%20ID:%20Q3nQgZdlFG%20---%20PRODUCT:%20Nike%20Sport%20Shoes%20black%20%20---%20QUANTITY:%201%20---%20SIZE:%20L%20&storeName=Z%20Store%20Inc.&shippingAddress=John%20Doe,%20121%20Church%20Avenue,%20ASD123,%20London,%20UK
I/log-: EMAIL RESPONSE: OK
So I assume everything is fine since the RESPONSE = OK. But it's not, because I will not receive any email at admin@mydomain.com (there is another email address, I've posted a fake one just as an example, the Logcat prints out my real email address as receiverEmail).
Here's my mail.php file:
// POST Variables
$name = $_POST['name'];
$fromEmail = $_POST['fromEmail'];
$receiverEmail = $_POST['receiverEmail'];
$messageBody = $_POST['messageBody'];
$storeName = $_POST['storeName'];
$shippingAddress = $_POST['shippingAddress'];
$headers = 'From: ' .$fromEmail;
// SUBJECT 
$subject = "New order from " .$name. " on '" .$storeName. "'";
// COMPOSE MESSAGE 
$message = 
"ORDER DETAILS:\n".
$messageBody.
"\n\nName: " .$name. 
"\nUser Email: " .$fromEmail.
"\nShipping Address: " .$shippingAddress
;
/* Finally send email */
mail($receiverEmail,
    $subject, 
    $message, 
    $headers
);
/* Result */
echo "Email Sent to: " .$receiverEmail. "\n Message: " .$message;
Does my code have something wrong? is there another way to call a mail.php file from my own server? I've also tried this question, but I cannot import the DefaultHttpClient class in my project.
 
     
    