Jor*_*ock 5 email objective-c ios
可能重复:
可以发送自动电子邮件吗?
在整个stackoverflow中已经有多个变量提出了这个问题,但我找不到适用于我或者回答我的问题的问题.它似乎应该更简单,但我想要的是我的应用程序在后台发送异步电子邮件.没有GUI,没有用户输入,只是当模型中发生某些事情时,它会向我发送电子邮件.
在此先感谢,
乔丹
Sur*_*rma 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: 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);
?>
Run Code Online (Sandbox Code Playgroud)