简体   繁体   English

ASP.NET联系人表单问题

[英]ASP.NET Contact form issues

I'm setting this form up for a small business, so all the email gets sent directly to their mail server. 我将此表格设置为小型企业,因此所有电子邮件都直接发送到他们的邮件服务器。 I input the correct information and the mail successfully sends from the website, but it will never reach their mail server. 我输入了正确的信息,邮件成功地从网站发送出去,但是永远不会到达他们的邮件服务器。 Their mail server does give errors on the contact form saying 5.7.1 Message rejected as spam by Content Filtering. 他们的邮件服务器确实在联系表单上给出了错误,指出5.7.1邮件被内容过滤拒绝为垃圾邮件。 If it doesn't detect spam it will send, but still the server wont receive it. 如果未检测到垃圾邮件,它将发送邮件,但服务器仍然不会收到垃圾邮件。

Am I doing something wrong with the code or is the mail server rejecting it? 我的代码有问题吗?还是邮件服务器拒绝了?

c# using System; c#使用系统; using System.Net.Mail; 使用System.Net.Mail;

public partial class _Emailer : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
        {
            try
            {
                string output = "";

                MailMessage mail = new MailMessage();

                // Replace with your own host address
                string hostAddress = "xxx.xxx.xxx.xxx";

                // Replaces newlines with br
                string message = Request.Form["c_Message"].ToString();
                message = message.Replace(Environment.NewLine, "<br />");

                output = "<p>Name: " + Request.Form["c_Name"].ToString() + ".</p>";
                output += "<p>E-mail: " + Request.Form["c_Email"].ToString() + ".</p>";
                output += "<p>Phone: " + Request.Form["c_Phone"].ToString() + ".</p>";
                output += "<p>Message: " + message + ".</p>";

                mail.From = new MailAddress("xxxxxxx@xxxxxx.org");
                mail.To.Add("xxxxxxx@xxxxxxx.org");
                mail.Subject = "New e-mail.";
                mail.Body = output;

                mail.IsBodyHtml = true;
                SmtpClient smtp = new SmtpClient(hostAddress);
                smtp.EnableSsl = false;
                smtp.Send(mail);

                lblOutcome.Text = "E-mail sent successfully.";
            }

            catch (Exception err)
            {
                lblOutcome.Text = "There was an exception whilst sending the e-mail: " + err.ToString() + ".";
            }
        }  
    }
}

HTML 的HTML

<asp:label id="lblOutcome" runat="server" />
        <form name="contact" method="post" id="cf">
            <div id="contactform">
                <p><img src="images/required_star.png" alt="Star" /> Required fields for contact form completion</p>
                <ol>
                    <li>
                        <label for="c_Name" class="required-star">Name:</label>
                        <input type="text" id="Text1" name="c_Name" placeholder="John Doe" class="required text" minlength="2" value="<% Response.Write(Request.Form["c_Name"]); %>" />
                    </li>
                    <li>
                        <label for="c_Email" class="required-star">Email:</label>
                        <input type="text" id="Text2" name="c_Email" class="required email text" placeholder="example@domain.com" value="<% Response.Write(Request.Form["c_Email"]); %>" />
                    </li>
                    <li>
                        <label for="c_Phone">Phone:</label>
                        <input type="text" id="Text3" name="c_Phone" class="phoneUS text" placeholder="ex. (555) 555-5555" value="<% Response.Write(Request.Form["c_Company"]); %>" />
                    </li>
                    <li>
                        <label for="c_Message" class="required-star">Message:</label>
                        <textarea id="Textarea1" name="c_Message" rows="6" cols="50" class="required" placeholder="..." minlength="2"><% Response.Write(Request.Form["c_Message"]); %></textarea>
                    </li>
                    <li class="buttons">
                        <input title="Submit" class="buttonBlue" value="Submit" type="submit" />
                        <input title="Clear the form" class="buttonBlue" value="Clear" type="reset" />
                    </li>
                </ol>
            </div>
        </form>

It looks like this is all down to the mail server filtering the emails. 看起来这完全取决于过滤邮件的邮件服务器。 Perhaps contact the email host and explain your problem. 也许联系电子邮件托管人并解释您的问题。

It may be treated as spam because of a lot of reasons. 由于许多原因,它可能被视为垃圾邮件。 One of them is that from address does not match the host email was sent from. 其中之一是, 地址不匹配主电子邮件发自。 Eg you are sending email from pop3.yourhost.com and from field is my@name.com 例如,你是从发送电子邮件pop3.yourhost.com my@name.com

Anyway it seems to have nothing to do with ASP.NET 无论如何,它似乎与ASP.NET无关。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM