プロジェクトで一度実装したので、HTTP Postを使用して 3 番目のオプションのヘルプを提供できるかもしれません。
まず、この素晴らしくシンプルな iOS クラスを使用して、投稿を処理しました。次に、次の iOS コード スニペットは、それがどのように行われたかを示します。
NSString* from = @"sender@email";
NSString* to = @"receiver@email";
NSString* mailCc = @"cc@email";
NSString* message = @"my message"
NSString* subject = @"my subject";
NSURL* url = [NSURL URLWithString:@"http://yourtestsite.com/my_email_script.php"];
//these are $_POST variables sent, so 'from' would be $_POST['from']
NSArray *keys = [[NSArray alloc] initWithObjects:@"from", @"to", @"cc", @"subject", @"message", nil];
NSArray *objects = [[NSArray alloc] initWithObjects:from, to, mailCc, subject, message, nil];
NSDictionary *dictionary = [[NSDictionary alloc] initWithObjects:objects forKeys:keys];
NSMutableURLRequest* request = [SimplePost urlencodedRequestWithURL:url andDataDictionary:dictionary];
NSURLResponse* response = [[NSURLResponse alloc] init];
NSError* error = [[NSError alloc] init];
NSData *returnData = [NSURLConnection sendSynchronousRequest: request returningResponse: &response error: &error];
NSString* result = [[NSString alloc] initWithData:returnData encoding:NSStringEncodingConversionAllowLossy];
//I'm checking for 1 because my php script was set to write 1 to the page in case of success and 0 otherwise, so this is simply my implementation
if([result isEqualToString:@"1"]) {
NSLog(@"success");
} else {
NSLog(@"error");
}
PHPファイルの場合、これでうまくいくはずです
$from = filter_var($_POST['from'], FILTER_SANITIZE_EMAIL);
$to = filter_var($_POST['to'], FILTER_SANITIZE_EMAIL);
$cc = filter_var($_POST['cc'], FILTER_SANITIZE_EMAIL);
$subject = htmlspecialchars(utf8_decode($_POST['subject']));
$message = utf8_decode($_POST['message']);
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'From: ' . $from . "\r\n";
$headers .= 'Cc: ' . $cc . "\r\n";
// Mail it
if(mail($to, $subject, $message, $headers)) {
echo("1");
} else {
echo("0");
}
私は PHP の専門家ではないので、特にセキュリティの部分でコードが改善される可能性があることを覚えておいてください。
[編集] PHP メーリングは、安価な共有アカウント、VPS、専用サーバーなど、ほとんどの主要なマネージド ホスティング ソリューションで既に有効になっているはずです。ただし、この方法で大量のメールを送信する予定がある場合は、専用サーバーをお勧めします.
ただし、送信できるメールの制限とmail
機能よりも優れたオプションがあります。詳細については、こちらを参照してください。
[後で編集] 作者が SimplePost クラスを削除したようです。ただし、同じ作成者が、 SimpleHTTPRequestと呼ばれる、役立つはずの代替手段を作成しました。残りは同じままにする必要があります