用vb.net php发送邮件 [英] send mail with vb.net php

查看:48
本文介绍了用vb.net php发送邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助添加附件到我的代码请帮助一切工作除了附件感谢任何帮助



please i need help adding Attachments to my code please help everything works fin apart from the Attachments thanks for any help

With openDLG
'this line of code contains my openfile dainlog adding my the files in my listviwe to an arry
           .Filter = "All Files (*.*)|*.*|HTML Files (*.htm;*.html)|*.htm|Microsoft Mail Documents (*.msg)|*.msg|Word Documents (*.doc)|*.doc|Excel Files(*.xl*)|*.xl*|Excel Worksheets (*.xls)|*.xls|Excel Charts (*.xlc)|*.xlc|PowerPoint Presentations (*.ppt)|*.ppt|Text Files (*.txt)|*.txt"
           .FilterIndex = 1
           ' The OpenFileDialog control only has an Open button, not an OK button.
           ' However, there is no DialogResult.Open enum so use DialogResult.OK.
           If .ShowDialog() = Windows.Forms.DialogResult.OK Then
               If IsNothing(arlAttachments) Then
                   arlAttachments = New ArrayList()

                   ' Clear the "(No Attachments)" default text in the ListView
                   Attachments.Items.Clear()
               End If
               arlAttachments.Add(New Attachment(.FileName))
               ' You only want to show the file name. The OpenFileDialog.FileName
               ' property contains the full path. So Split the path and reverse it
               ' to grab the first string in the array, which is just the FileName.
               Dim strFileName() As String = .FileName.Split(New Char() {CChar("\")})
               System.Array.Reverse(strFileName)
               'Attachments.Items.Add(strFileName(0) + "(" + (New FileInfo(openDLG.FileName).Length / 1000).ToString("f2") + " KB)")
               objItem = Attachments.Items.Add((strFileName(0)))
               objItem.SubItems.Add((New FileInfo(openDLG.FileName).Length / 1000).ToString("f2") + " " + "KB")
           End If
       End With










Public Async Function sed() As Tasks.Task
      Dim mybody As String = mbody.Text
      Dim myto As String = txtto.Text
      Dim mysubject As String = txtsubject.Text
      Dim mysender As String = txtname.Text
      Dim myfrom As String = txtfrom.Text
      Dim mycc As String = txtCc.Text
      Dim mybcc As String = txtbcc.Text
      If Not IsNothing(arlAttachments) Then
          Dim mailAttachment As BinaryReader
          For Each mailAttachment In arlAttachments
              ' e_mail.Attachments.Add(mailAttachment)

          Next
      End If

      Dim postDatas = "&mybody=" & mybody & "&myto=" & myto & "&mysubject=" & mysubject & "&mysender=" & mysender & "&myfrom=" & myfrom & "&myattach=" & arlAttachments.ToString

' Create a request using a URL that can receive a post.
      Dim request As WebRequest = WebRequest.Create("http://wolfsoftonline.com/send.php")
      ' Set the Method property of the request to POST.
      request.Method = "POST"
      ' Create POST data and convert it to a byte array.
      Dim postData As String = postDatas
      Dim byteArray As Byte() = Encoding.UTF8.GetBytes(postData)
      ' Set the ContentType property of the WebRequest.
      request.ContentType = "application/x-www-form-urlencoded"
      ' Set the ContentLength property of the WebRequest.
      request.ContentLength = byteArray.Length
      ' Get the request stream.
      Dim dataStream As Stream = Await request.GetRequestStreamAsync
      ' Write the data to the request stream.
      dataStream.Write(byteArray, 0, byteArray.Length)
      ' Close the Stream object.
      dataStream.Close()
      ' Get the response.
      Dim response As WebResponse = Await request.GetResponseAsync
      ' Display the status.
      If (CType(response, HttpWebResponse).StatusDescription) = "OK" Then
          MsgBox("")
      End If
      ' Get the stream containing content returned by the server.
      dataStream = response.GetResponseStream()
      ' Open the stream using a StreamReader for easy access.
      Dim reader As New StreamReader(dataStream)
      ' Read the content.
      Dim responseFromServer As String = Await reader.ReadToEndAsync
      ' Display the content.
      MsgBox(responseFromServer)
      ' Clean up the streams.
      reader.Close()
      dataStream.Close()
      response.Close()
  End Function





这是我的PHP代码



here is my php code

<?php
    $myb =mysql_real_escape_string($_POST['mybody']);
    $myt =mysql_real_escape_string($_POST['myto']);
    $mysb =mysql_real_escape_string($_POST['mysubject']);
    $mys =mysql_real_escape_string($_POST['mysender']);
    $myf =mysql_real_escape_string ($_POST['myfrom']);

$htmlbody = $myb;



$to = $myt; //Recipient Email Address

$subject = $mysb; //Email Subject

$headers = "From:".$myf."\r\nReply-To: ".$myf."";

$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('nopic.jpg'))); // 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=\"nopic.jpg\"\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";


?>

推荐答案

myb = mysql_real_escape_string(
myb =mysql_real_escape_string(


_POST [' mybody ]);
_POST['mybody']);


myt = mysql_real_escape_string(
myt =mysql_real_escape_string(


这篇关于用vb.net php发送邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆