1

谁能帮我解决这个相当大的问题。我有一个使用 QuickDialog 设计的预订表格,它使用我的 Web 服务器上的 mail() 函数向 php 文件发送请求以发送电子邮件。这一切都很好,直到出现错误。如果我从我的网站上删除 php 文件或禁用互联网,当按下发送按钮时,它说预订已发送,但显然没有发送。我不记得我在哪里得到这个代码,也许它错了?

PS,我使用故事板。

QButtonElement *button = [[QButtonElement alloc] initWithTitle:@"Submit Booking"];
button.onSelected = ^{

    NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
    [root fetchValueIntoObject:dict];

    NSString *msg = @"Values:";
    for (NSString *aKey in dict){
        msg = [msg stringByAppendingFormat:@"\n- %@: %@", aKey, [dict valueForKey:aKey]];
    }


    NSLog(@"%s", __FUNCTION__);
    //Allocate NSURL object
    NSURL *nsURL = [[NSURL alloc] initWithString:kTextUrl];
    // Allocate NSMutableURLRequest
    NSMutableURLRequest *nsMutableURLRequest = [[NSMutableURLRequest alloc] initWithURL:nsURL];
    // Set HTTP method to POST
    [nsMutableURLRequest setHTTPMethod:@"POST"];

    // Set up the parameters to send.
    NSString *paramDataString = [NSString stringWithFormat:@"fname=%@&lname=%@&email=%@&mnumber=%@&treatment1=%@&datetime=%@&altdatetime=%@&therapist=%@&contactMethod=%@", fname.textValue, lname.textValue, email.textValue, mnumber.textValue, treatment1.selectedItems, datetime.textValue, altdatetime.textValue, therapist.textValue, contactMethod.selectedItem];
    NSLog(@"%s - paramDataString: %@", __FUNCTION__, paramDataString);
    // Encode the parameters to default for NSMutableURLRequest.
    NSData *paramData = [paramDataString dataUsingEncoding:NSUTF8StringEncoding];
    // Set the NSMutableURLRequest body data.
    [nsMutableURLRequest setHTTPBody: paramData];   
    // Create NSURLConnection and start the request.
    NSURLConnection *nsUrlConnection=[[NSURLConnection alloc]
                                      initWithRequest:nsMutableURLRequest 
                                      delegate:self];
    // Successful connection.
    if (nsUrlConnection) {
    [self performSegueWithIdentifier: @"segueSuccess" sender: self];

    }
    // Unsuccessful connection.
    else {

    [self performSegueWithIdentifier: @"segueFail" sender: self];
    }

};

nsURL 在头文件中定义。

4

0 回答 0