Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 727905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:37:14+00:00 2026-05-14T06:37:14+00:00

I have a PHP script on a server <?php // retrieve POST vars $comment

  • 0

I have a PHP script on a server

<?php

// retrieve POST vars
$comment = $_POST['comment'];
$email = $_POST['email'];

// remove trailing whitespace etc
$comment = trim($comment);
$email = trim($email);

// format date accoring to http://www.w3schools.com/php/func_date_date.asp
$date_time = date("Y-m-d-H-i-s"); // i.e. 2010-04-15-09-45-23

// prepare message
$to = "(removed my email addy)"; //who to send the mail to
$subject = "Feedback from iPhone app"; //what to put in the subject line
$message = "Name/Email: $email \r\n Comment: $comment";
  mail($to, $subject,$message) or "bad";

echo "ok";
?>

How do I now send a POST request from my iPhone app…

ive tried this sort of thing…

NSURL *url = [NSURL URLWithString:@"mysite.com/script.php"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];

NSString *message = boxForSuggestion.text;
NSString *userEmailString = usersEmail.text;


NSString *requestBodyString = [NSString stringWithFormat:@"comment:%@&email%@", message , userEmailString];

NSData *requestBody = [requestBodyString dataUsingEncoding:NSUTF8StringEncoding];
[request setHTTPMethod:@"POST"
[request setHTTPBody:requestBody];
 [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"content-type"]; // added from first suggestion 
NSURLResponse *response = NULL;
NSError *requestError = NULL;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&requestError];
NSString *responseString = [[[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding] autorelease];

NSLog(@"%@", responseString);

Any ideas? Thanks guys

Sam

EDIT:

i think there is something wrong with my request body

NSData *requestBody = [requestBodyString dataUsingEncoding:NSUTF8StringEncoding];
[request setHTTPMethod:@"POST"
[request setHTTPBody:requestBody];

remember that my php variables are $comment and $email

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T06:37:14+00:00Added an answer on May 14, 2026 at 6:37 am

    try to add:

    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"content-type"];
    

    After:

    [request setHTTPBody:requestBody];
    

    In your script

    Edit:

    Since I don’t have a sdk available I can’t test it for you but could you try this?:

    NSURL *url = [NSURL URLWithString:@"mysite.com/script.php"];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    
     NSString *requestBodyString = [NSString stringWithFormat:@"comment=%@&email=%@", message , userEmailString];
     NSData *requestBody = [NSData dataWithBytes:[requestBodyString UTF8String]length:[requestBodyString length]];
    
     [request setHTTPMethod:@"POST"
     [request setHTTPBody:requestBody];
     [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"content-type"]; // added from first suggestion 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a PHP script running on my LAMP server that requires certain files
I have a php mail script sitting on a LAMP vps server. The script
My server have default php version of 4, so when I run some script
I have a PHP script that is using get_dns_record to retrieve and display specific
I have written a PHP script below try to Post the JSON encoded string
I have a server-side php-script that fetches results from a MySQL table. I am
Instead of POST-ing to a server PHP file to retrieve JSON structured data. Is
I have a php script http://example.com/myapp/myscript.php running on an Apache server. I call this
I have a php script to retrieve data from a MysQL databse following an
I have a php script which requires no web hosting or disk space etc.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.