0

我有一个小问题,希望您可以提供帮助。

我有一个 Email.html 页面,它要求用户输入我也想向其发送电子邮件的电子邮件地址:

<section id="dialog" class="window">
<h1>Email Me <a href="#" class="close"/>Close</a></h1>  

  <p>Email Details To</p>
    <input type="email" placeholder="email address" autofocus class="input-    email" id="email">

  <p id="email-entry" class="error disp-none">Please enter an email address</p>
  <p id="email-valid" class="error disp-none">Please enter a valid email address</p>

  <input type="button" value="Send" id="btn-send">

我有一个 aspx.vb 文件,我希望它能够“处理”电子邮件:

Imports System.Net.Mail

Partial Class ContactUs
Inherits System.Web.UI.Page

Protected Sub SendMails_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles SendMails.Click

Dim FromPersonName As String = FromName.Text
    Dim FromPersonEmail As String = “sales@test.co.uk”
    Dim FromPersonContactNumber As String = FromContactNumber.Text
    Dim EmailSubject As String = Subject.Text
    Dim ToAddress As String = email.input

    '(1) Create the MailMessage instance
    Dim mm As New MailMessage(FromEmail.Text, ToAddress)

    '(2) Assign the MailMessage's properties
    mm.Subject = Subject.Text
    mm.Body = "Thank you for your enquiry. A member of our team will contact you shortly.”
    mm.IsBodyHtml = False

    '(3) Create the SmtpClient object
    Dim smtp As New SmtpClient

    '(4) Send the MailMessage (will use the Web.config settings)
    smtp.Send(mm)

    EmailSentForm.Visible = True
    SendMails.Visible = False

End Sub
End Class

最后,访问我的服务器的 web.config 文件:

<system.net>
    <mailSettings>
        <smtp>
            <!--    <network host="yourRELAYSERVERHOSTNAME" port="yourPORTNUMBER" userName="yourUSERNAME" password="yourPASSWORD" /> -->

        </smtp>
    </mailSettings>
</system.net>

如何将这些文件集成在一起(如果可能),所以当用户在 .html 页面中输入电子邮件地址时,会调用 .aspx.vb 脚本和 web.config?

对于我想要实现的目标,是否有更简单的解决方案?

任何帮助表示赞赏,谢谢。

4

1 回答 1

0

您正在寻找的是所谓的 AJAX。我认为您只需要修改您的 aspx 代码即可将某种响应返回到您的 HTML 页面/AJAX 请求。

success如果邮件已发送,假设您的 aspx 页面以文本形式返回,只需编写:

$.get('aspx.vb', {email: $('#email').val()}, function (data) {
   if (data === 'success') {
       alert('Email has been sent successfully');
   } else {
       alert('Oops, There was some problem.');
   }
});

演示:http: //jsfiddle.net/DDaJQ/

希望这可以帮助!

于 2012-08-16T09:42:43.567 回答