I am trying to send registration/ activation information via email, but don't want to store my authentication within the vb.net app and therefore not wanting to use .NET SMTP. I have the below php script that works from a website, but I can't seem to get the variables sent to it using the code posted. Any advice with either the .NET code or the php code?

Thanks in advance.

Dim errorString As String = "test string"
        Dim postData = "errorString=" & errorString

        Dim request As WebRequest = WebRequest.Create("http://webaddress.com/test.php")

        request.Method = "POST"
        Dim byteArray As Byte() = Encoding.UTF8.GetBytes(postData)
        request.ContentType = "application/x-www-form-urlencoded"
        request.ContentLength = byteArray.Length
        Dim dataStream As Stream = request.GetRequestStream()
        dataStream.Write(byteArray, 0, byteArray.Length)
        dataStream.Close()
        Dim response As WebResponse = request.GetResponse()
        dataStream = response.GetResponseStream()
        Dim reader As New StreamReader(dataStream)
        Dim responseFromServer As String = reader.ReadToEnd()
        reader.Close()
        dataStream.Close()
        response.Close()
        MsgBox(responseFromServer)
<?php
$Name = $_REQUEST['Name'] ;
$Email = $_REQUEST['Email'] ;
$Address = $_REQUEST['Address'] ;
$Phone = $_REQUEST['Phone'] ;
$Member = $_REQUEST['Member'] ;
$Comments = $_REQUEST['Comments'] ;

$Message = "Name: $Name\nEmail: $Email\nPhone Number: $Phone\nAddress: $Address\nMember: $Member\nComments: $Comments" ;

mail( "address@email.com", "You Have Received a Registration", "Information Requested:\n\n$Message","From: $Email" );

echo "This following information was submitted successfuly.<br>Name: $Name<br>Email: $Email<br>Phone Number: $Phone<br>Address: $Address<br>Member: $Member<br>Comments: $Comments" ;
?>

GeekByChoiCe,
Thanks for the speedy reply, but I just want to see if there will be any information visible to the user as this sub runs? I will be collecting some information from the local machine to run an activation hash on so I don't want them seeing what I am sending for obvious reasons. I will obfusicate my code to further this effort, but if this will be sent and easily caught midstream then I will look for another route.

Thanks again.

When I edit the code as suggested, all that is returned to me is the HTML of the main homepage for the site http://webaddress.com and of course no email is sent. Can you comment on the php code as to if it is correct for this kind of method? Do I need to use GET rather than REQUEST?

Thanks.

This is what my final vb.net code ended up as. This is working for what I need currently, but it can be expanded upon for someone elses needs.

Imports System.Net
Imports System.Text
Imports System.IO

Dim Name As String = "Name"
        Dim Email As String = "E@mail.com"
        Dim Phone As String = "8979876785"
        Dim Address As String = "Location"
        Dim postData = "&Name=" & Name & "&Email=" & Email & "&Phone=" & Phone & "&Address=" & Address

        Dim request As WebRequest = WebRequest.Create("http://www.webaddress.com/test.php")

        request.Method = "POST"
        Dim byteArray As Byte() = Encoding.UTF8.GetBytes(postData)
        request.ContentType = "application/x-www-form-urlencoded"
        request.ContentLength = byteArray.Length
        Dim dataStream As Stream = request.GetRequestStream()
        dataStream.Write(byteArray, 0, byteArray.Length)
        dataStream.Close()
        Dim response As WebResponse = request.GetResponse()
        dataStream = response.GetResponseStream()
        Dim reader As New StreamReader(dataStream)
        Dim responseFromServer As String = reader.ReadToEnd()
        reader.Close()
        dataStream.Close()
        response.Close()
        MsgBox(responseFromServer)

This is the associated PHP code that I was using for testing purposes. It will give you the variables back each on a new line. Also, make sure your .htaaccess file allows direct linking. This was part of the issue i was having.

<?php
$a = $_POST['Name'];
$b = $_POST['Email'];
$c = $_POST['Phone'];
$d = $_POST['Address'];
 echo "$a\n$b\n$c\n$d"  ;
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.