Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
Dim Names As String = txtfrom.Text
        Dim Email As String = "E@mail.com"
        Dim Phone As String = "8979876785"
        Dim Address As String = "Location"
        Dim postData = "&Names=" & Names & "&Email=" & Email & "&Phone=" & Phone & "&Address=" & Address
        Dim request As WebRequest = WebRequest.Create("http://localhost/testserver/sendmail.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)


and my php code is
PHP
<?php

$htmlbody = " Your Mail Contant Here.... You can use html tags here...";



$to = "name@domain.com"; //Recipient Email Address

$subject = "Test email with attachment"; //Email Subject

$headers = "From: name@domain.com\r\nReply-To: name@domain.com";

$random_hash = md5(date('r', time()));

$headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";

$attachment = chunk_split(base64_encode(file_get_contents('logo.png'))); // Set your file path here

//define the body of the message.

$message = "--PHP-mixed-$random_hash\r\n"."Content-Type: multipart/alternative; boundary=\"PHP-alt-$random_hash\"\r\n\r\n";
$message .= "--PHP-alt-$random_hash\r\n"."Content-Type: text/plain; charset=\"iso-8859-1\"\r\n"."Content-Transfer-Encoding: 7bit\r\n\r\n";

//Insert the html message.
$message .= $htmlbody;
$message .="\r\n\r\n--PHP-alt-$random_hash--\r\n\r\n";

//include attachment
$message .= "--PHP-mixed-$random_hash\r\n"."Content-Type: application/zip; name=\"logo.png\"\r\n"."Content-Transfer-Encoding: base64\r\n"."Content-Disposition: attachment\r\n\r\n";
$message .= $attachment;
$message .= "/r/n--PHP-mixed-$random_hash--";

//send the email
$mail = mail( $to, $subject , $message, $headers );

echo $mail ? "Mail sent" : "Mail failed";


?>

how do i pass the parameters to my php script thanks for your help
Posted
Comments
Simon_Whale 25-Dec-14 7:57am    
is the VB.NET code a service?
Wolfsoftonline 25-Dec-14 8:00am    
no am using httpWebRequest
Wolfsoftonline 25-Dec-14 12:25pm    
pls i need help asap
Praveen Kumar Upadhyay 26-Dec-14 9:33am    
Why OP has removed the accepted answers?
Wolfsoftonline 26-Dec-14 9:38am    
because i need farther help

In Php you can get the request data using $_REQUEST["<parameter name="">"].
So rather using below code.
PHP
$to = "name@domain.com"; //Recipient Email Address


Use something like
PHP
$to = $_REQUEST["Email"];


similarly you can accept all required parameter which is been posted to this php page.
 
Share this answer
 
one way is passing parameters as query string to your php page. for example you can request
"http://localhost/testserver/sendmail.php?A=aaa&B=bbbbb"

in the php page you can get the values as below
PHP
$A = $_SERVER['A'];
$B = $_SERVER['B'];
 
Share this answer
 
Comments
Wolfsoftonline 26-Dec-14 3:54am    
how about this will it work


$myb = $_POST['mybody'];
$myt = $_POST['myto'];
$mysb = $_POST['mysubject'];
$mys = $_POST['mysender'];
$myf = $_POST['myfrom'];

$htmlbody = $myb;

Dim postData = "&mybody=" & mybody & "&myto=" & myto & "&mysubject=" & mysubject & "&mysender=" & mysender & "&myfrom=" & myfrom
Dim request As WebRequest = WebRequest.Create("http://localhost/testserver/sendmail.php")
Wolfsoftonline 26-Dec-14 5:11am    
thanks guys the post function worked fine but the only problem am having is with the attachment.
Wolfsoftonline 26-Feb-15 3:00am    
how do i Get funtion data into a string

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900