6

可能重复:
可以发送自动电子邮件吗?

这个问题在整个 stackoverflow 中以多种变体形式提出,但我找不到一个适用于我或回答我的问题的问题。看起来它应该更简单,但我想要的只是让我的应用程序在后台发送异步电子邮件。没有 GUI,没有用户输入,只是当模型中发生某些事情时,它会通过电子邮件通知我。

在此先感谢,
乔丹

4

1 回答 1

14

IOS不支持后台发邮件。您必须实现用户交互,并且只有单击发送按钮才能发送邮件。作为替代方案,您应该为此实现 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:  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);
?>
于 2012-04-17T06:10:01.187 回答