简体   繁体   中英

how to send a POST value to a server with a PHP script waiting for it from iPhone app

In my iPhone app - I am trying to get what the user types in a box emailed to me. I am going to use a PHP script sitting on my server, and try send the data to it for it to be processed.

Promblem is... how do i do this?

Im using the ASIHTTPRequest wrapper and have some code like this

ASIFormDataRequest *request = [[[ASIFormDataRequest alloc] initWithURL:url] autorelease];
[request setPostValue:@"example@mail.com" forKey:@"address"];
[request setPostValue:@"mymessagehere" forKey:@"message"];

and have this simple php script which i plan to use here http://www.w3schools.com/PHP/php_mail.asp

How do I go about joining these up?

Any tutorial links/blog post/ideas appreciated

Doesn't matter that you're using an iphone to do the POST, on the server it's all handled the same. All POST data will be placed into the $_POST and $_REQUEST associative arrays, from which you'd retrieve whatever you need to email. The script would look something like this:

<?php

$message = '';
foreach ($_POST as $key => $val) {
    $message .= "$key => $val\n";
}

mail('user@example.com', 'Subject goes here', $message);

?>

If you want to send an HTML-formatted mail, then I'd suggest using something like PHPMailer , which can handle the nitty-gritty details of generating MIME-based emails.

If you need to test the script to see that your iphone app is doing the POST request properly, you can always just have it echo back the POST data:

<?php var_dump($_POST); ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM