2012-04-17 71 views
5

可能重複:
Possible to send automated email?發送電子郵件在後臺從iOS的

這個問題已經被問在整個計算器多種變化,但我不能完全找到一個適用於我或者回答我的問題。它似乎應該更簡單,但我想要的是我的應用程序在後臺發送異步電子郵件。沒有圖形用戶界面,也沒有用戶輸入,只是當模型發生某些事情時,它會通過電子郵件向我發送有關它的信息

由於提前,
喬丹

回答

13

IOS並不郵件支持背景。您必須實施USer互動&只有點擊發送按鈕纔會發送郵件。 作爲一種替代方案,您應該爲此&實施WebService,您可以在代碼中的任何位置調用它。

PHP要求:

<?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: [email protected]_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); 
?> 
+0

謝謝,回答了完美。沒有其他答案有任何意義 – 2012-04-17 17:55:34

+3

我不明白爲什麼這是封閉的。我所能找到的所有「重複」答案都指的是三年內未更新的圖書館,但並未受到用戶的熱烈接受,並且在文檔中聲明,它對於簡單的文本電子郵件來說是非常需要的。 Suresh提供了我發現的最接近於如何發送簡單文本而不需要UI的電子郵件的直接答案。我想了解更多關於如何正確實施它的信息。 – 2012-06-11 13:51:25

+0

是的,確切地說,這不應該被關閉,因爲被引用的庫不足以工作。即使您執行,Apple也不支持。在appStore中查看App時,它可能會受到限制。 – 2012-06-13 10:54:56