6

Possible Duplicate:
Possible to send automated email?

This question has been asked in multiple variations throughout stackoverflow, but I can't quite find one that applies to me or that answers my question. It seems like it should be more simple but all I want is for my app to send an asynchronous email in the background. No GUI, no user input, just that when something happens in the model it emails me about it.

Thanks in advance,
Jordan

Community
  • 1
  • 1
Jordan Medlock
  • 807
  • 1
  • 8
  • 21

1 Answers1

14

IOS doesn't support to mail in background. You must implement the USer interaction & only clicking over send button will be sending the mail. As an alternate you should implement the WebService for this & you can call it anywhere in you code.

php required:

<?php
//-- POST are variables from details.js
$names      = $_POST['names'];
$address1   = $_POST['address1'];
$address2   = $_POST['address2'];
$crust      = $_POST['crust'];
$message1   = $_POST['message'];

//-- clean up the javascript array
$toppings   = str_replace('"','',substr(substr(stripslashes($_POST['toppings']),1),0,-1));
$toppings   = explode(",\n", $toppings);

//-- Where the order will be sent
$to = $address2;
$subject = "your_Order!";
$message = $message1 ;

//-- The headers will let us send HTML code as an email
$headers = "From:  contact@your_domain.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

//-- if mail gets sent, return true, else return false. This gets handed off the our onload method in details.js
if (mail($to,$subject,$message,$headers))
{
    $response = array('mail' => true);
}
else
{
    $response = array('mail' => false);
}

echo json_encode($response);
?>
Suresh Sharma
  • 1,826
  • 22
  • 41
  • Thank you, answered it perfectly. None of the other answers made any sense – Jordan Medlock Apr 17 '12 at 17:55
  • 3
    I can't understand why this was closed. All the "duplicate" answers I could find refer to a library that hasn't been updated in three years, is less than enthusiastically accepted by users and states right in the documentation that it is more than needed for simple text emails. Suresh has provided the closest I have found to a direct answer for how to send simple text only email without UI. I would like more info on how to implement it properly myself. – Dean Davids Jun 11 '12 at 13:51
  • yes, exactly this shouldn't be closed because the Library that is referred is not enough to work.Apple doesn't support even you implement.it may be restricted When reviewing the App in appStore. – Suresh Sharma Jun 13 '12 at 10:54
  • Another reason it shouldn't be closed is because not everyone can go with what's here. I like the idea of using a server to do the emailing but I don't know how to call it from my iOS code. And if/how to get the response. – Troy Sartain Oct 04 '12 at 02:46