1

Just finished an automatic newsletter-subscriber module written in C#. Now I have to translate it in PHP so I can use it with my wordpress sites as well. I'm not that good in PHP as most of the time I'm writting .NET MVC applications. In C# I came up with the following solution:

// Code below runs each time a user submits the newsletter form
using (var client = new WebClient()) {

    var MyValues = new NameValueCollection();
    MyValues["list"] = "123456789";
    MyValues["boolean"] = "true";
    MyValues["name"] = model.NameSec;
    MyValues["email"] = model.EmailSec;

    var MyResponse = client.UploadValues("http://www.XXXXXX.com/subscribe", MyValues);

    var MyValue = Encoding.Default.GetString(MyResponse);

    if (MyValue.Equals("true")) {
            // All correct
    }
    else {
            // Oops, smth went wrong
    }

}

Now I'm looking for a similar method as WebClient.UploadValues but for PHP. Could you please give me some guidance?

1 Answers1

0

WebClient.UploadValues() is making a POST request to your URI. To achieve the same in PHP, you should look into Curl. There are plenty of examples available and a number of questions that already address the topic.

This is probably the best answer with source code/examples.

Sam Pride
  • 387
  • 2
  • 5