如何让我的Vb.Net程序从Php发送电子邮件 [英] How Do I Make My Vb.Net Program Send Email From Php
本文介绍了如何让我的Vb.Net程序从Php发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Dim 名称作为 字符串 = txtfrom.Text
Dim 电子邮件作为 字符串 = E@mail.com
Dim 电话作为 字符串 = 8979876785
Dim 地址< span class =code-keyword> As String = 位置
Dim postData = & Names =&姓名& & Email =&电子邮件& & Phone =&电话& & Address =&地址
Dim request As WebRequest = WebRequest.Create( http://localhost/testserver/sendmail.php)
request.Method = post
Dim byteArray 作为 字节()= 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 响应 As WebResponse = request.GetResponse()
dataStream = response.GetResponseStream()
Dim reader As 新 StreamReader(dataStream)
Dim responseFromServer As String = reader .ReadToEnd()
reader.Close()
dataStream.Close()
response.Close()
MsgBox(responseFromServer)
和我的PHP代码是
<?php
$ htmlbody = 你的邮件在这里......你可以在这里使用html标签......;
$ to = name@domain.com跨度>; // 收件人电子邮件地址
$ subject = 测试带附件的电子邮件; // 电子邮件主题
$ headers = 来自:name@domain.com \\\\ nnReply-To:name @ domain.com跨度>;
$ random_hash = md5(date(' r',time()));
$ headers 。= \r\\\
Content-Type:multipart / mixed; boundary = \PHP-mixed - 。$ random_hash。 \ 跨度>;
$ attachment = chunk_split(base64_encode(file_get_contents(' logo.png跨度>))); // 在此处设置文件路径
// 定义消息正文。
$ message = - PHP-mixed- $ random_hash \\\\ n。 Content-Type:multipart / alternative; boundary = \PHP-alt- $ random_hash \\ r \\\
\r\\\
跨度>;
$ message 。= - PHP -alt- $ random_hash\r\ n。 Content-Type:text / plain; charset = \iso-8859-1 \\\\\ n。 内容传输编码:7bit \\\\\\\ n;
// 插入html消息。
$ message 。= $ htmlbody ;
$ message 。= \ r \\\
\r\\\
- PHP - 交替 - $ random_hash - \r\\\
\r\\\
跨度>;
// 包含附件
$ message 。= - PHP-mixed- $ random_hash\\\\ n。 Content-Type:application / zip; name = \logo.png \ \\\\ n。 Content-Transfer-Encoding:base64 \\\ n。 Content-Disposition:attachment \\\\\\\ n 跨度>;
$ message 。= $ attachment ;
$ message 。= / r / N - PHP-混色$ random_hash - 跨度>;
// 发送电子邮件
$ mail = mail($ to, $ subject ,$ message, $ headers );
echo $ mail ? 已发送邮件: 邮件失败;
?>
如何传递参数感谢您的帮助
解决方案
htmlbody = 你的邮件在这里......你可以在这里使用html标签......;
to = name@domain.com; // 收件人电子邮件地址
subject = 测试带附件的电子邮件跨度>; // 电子邮件主题
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
$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
解决方案
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
这篇关于如何让我的Vb.Net程序从Php发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文