I'm trying to create a simple, completely stand-alone ASP script that reads GET variables posted from a jQuery ajax call and then sends an email based on some of those values. However, I am completely new to ASP and having some trouble converting it.
我正在尝试创建一个简单的,完全独立的ASP脚本,它读取从jQuery ajax调用发布的GET变量,然后根据其中的一些值发送电子邮件。但是,我对ASP完全不熟悉并且在转换它时遇到了一些麻烦。
From my research, it appears that the ASP equivalent of $_GET['var_name'] is Request.QueryString['var_name']. However, with sending an email, I have stumbled across dozens and dozens of examples using everything from ASPEmail, CDOSYS, IPWorksMail, JMail, and so on. I have tried a few and I tend to get no positive results.
根据我的研究,似乎$ _GET ['var_name']的ASP等价物是Request.QueryString ['var_name']。然而,通过发送电子邮件,我偶然发现了数十个和几十个使用ASPEmail,CDOSYS,IPWorksMail,JMail等所有内容的例子。我尝试了一些,我倾向于没有得到积极的结果。
Here is what I'm trying to accomplish in ASP, written in PHP:
以下是我在ASP中尝试完成的内容,用PHP编写:
<?php
if($_GET['val1'] != "") {
// Add section one to the email.
}
if($_GET['val2'] != "") {
// Add section two to the email
}
$email_company = mail($_GET['company_email'], $subject, $message, $headers);
$email_client = mail($_GET['client_email'], $subject, $message, $headers);
if($email_company && $email_client) {
echo 'success';
}
else {
echo 'error';
}
?>
So, what should I be looking to use for emails? Can I made this page standalone, so that it can sit by itself and receive AJAX calls? Thank you for your time.
那么,我应该将什么用于电子邮件呢?我可以将此页面设置为独立,以便它可以单独使用并接收AJAX调用吗?感谢您的时间。
EDIT:
I have been trying stuff like this and I without fail get a 500 server error. I cannot view any error messages as all I get is a 500 page, so I don't know where to look for the problem.
我一直在尝试这样的东西,我没有失败得到500服务器错误。我无法查看任何错误消息,因为我得到的是500页,所以我不知道在哪里寻找问题。
<%=
' Create the Mail Message
Dim Mail As New MailMessage
' Set the address information
Mail.From = New MailAddress("from@website.com")
Mail.To.Add("to@website.com")
' Set the content of the email
Mail.Subject = "Testing Email"
Mail.Body = "Hello, I am a test email!"
' Send the message
Dim SMTP As New SmtpClient("MAIL SERVER")
SMTP.EnableSsl = False
SMTP.Credentials = New System.Net.NetworkCredential("USERNAME", "PASSSWORD")
SMTP.Port = 25
SMTP.Send(Mail)
%>
1 个解决方案
#1
0
Here's an example using a standalone page and a webmethod. If you're still having problems, it could be an issue with your web server configuration. If you're using IIS, make sure you've set up the page in either a virtual directory or an application inside of a website with the proper bindings. Try making a simple html page at the location to make sure the page is reachable (and "where" you think it is).
这是一个使用独立页面和webmethod的示例。如果您仍然遇到问题,则可能是您的Web服务器配置存在问题。如果您使用的是IIS,请确保已使用正确的绑定在虚拟目录或网站内的应用程序中设置页面。尝试在该位置创建一个简单的html页面,以确保页面可以访问(以及“您认为它在哪里”)。
Cheers.
<%@ Page Language="C#" %>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<script>
$(function () {
var params = {};
params['from'] = 'fake@test.com'
params['to'] = 'fakeone@test.com;faketwo@test.com';
params['body'] = 'hello world';
$.ajax({
type: 'POST',
url: 'default.aspx/SendMail',
data: JSON.stringify(params),
contentType: 'application/json; charset=utf-8',
dataType: "json"
});
});
</script>
<script runat="server">
[System.Web.Services.WebMethod]
public static void SendMail(string to, string from, string body)
{
var mail = new System.Net.Mail.MailMessage();
mail.Body = body;
mail.From = new System.Net.Mail.MailAddress(from);
foreach (var r in to.Split(';'))
mail.To.Add(r);
var smtp = new System.Net.Mail.SmtpClient("mail.yourdomain.com");
smtp.Send(mail);
}
</script>
#1
0
Here's an example using a standalone page and a webmethod. If you're still having problems, it could be an issue with your web server configuration. If you're using IIS, make sure you've set up the page in either a virtual directory or an application inside of a website with the proper bindings. Try making a simple html page at the location to make sure the page is reachable (and "where" you think it is).
这是一个使用独立页面和webmethod的示例。如果您仍然遇到问题,则可能是您的Web服务器配置存在问题。如果您使用的是IIS,请确保已使用正确的绑定在虚拟目录或网站内的应用程序中设置页面。尝试在该位置创建一个简单的html页面,以确保页面可以访问(以及“您认为它在哪里”)。
Cheers.
<%@ Page Language="C#" %>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<script>
$(function () {
var params = {};
params['from'] = 'fake@test.com'
params['to'] = 'fakeone@test.com;faketwo@test.com';
params['body'] = 'hello world';
$.ajax({
type: 'POST',
url: 'default.aspx/SendMail',
data: JSON.stringify(params),
contentType: 'application/json; charset=utf-8',
dataType: "json"
});
});
</script>
<script runat="server">
[System.Web.Services.WebMethod]
public static void SendMail(string to, string from, string body)
{
var mail = new System.Net.Mail.MailMessage();
mail.Body = body;
mail.From = new System.Net.Mail.MailAddress(from);
foreach (var r in to.Split(';'))
mail.To.Add(r);
var smtp = new System.Net.Mail.SmtpClient("mail.yourdomain.com");
smtp.Send(mail);
}
</script>