电子邮件中的表格 [英] Form inside a E-Mail Message

查看:153
本文介绍了电子邮件中的表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有一份工作要由我的雇主来做.这是一个非常有趣的.我必须发送一封包含用户输入表格的电子邮件.当用户单击提交"按钮时,必须将另一封邮件连同该信息一起发送回发件人.我已经使用Gmail正确完成了(一切正常).但是使用Yahoo时,它进入了垃圾邮件,而我却绕过了垃圾邮件,但是当用户单击提交"按钮时,它将重定向到其他页面.逻辑是使用HTML表单标签发送一封包含isBodyHTML true的电子邮件,操作是get,而url是服务器url,我在其中创建用于处理用户输入的数据的文件并发送邮件.我已经使用gmail smtp进行了测试
代码如下:

第一封电子邮件发送代码

Hi,
I have got a job to do from my employer. It is a very funny one. I have to send an e-mail containing an user input form. When the user clicks the submit button another mail must be sent back to the sender with the information. I have done it properly with Gmail (every thing works fine). But with Yahoo it goes in spam which i bypassed but when the user clicks the submit button it redirects to some other page. The logic was to send an email with isBodyHTML true using HTML form tags action was get and url was the servers url where i created the file for proceesing the data inpuuted by user and send the mail.I have used the gmail smtp for testing
the code is given below:

First Email Sending Code

public string mailbody()
    {
        string strbody="";
        strbody+="<html>";
        strbody+="<body>";
        strbody += "<form id = form1 method=get action=\"url here\">";
   
        strbody += "Name: <input type=text name=\"a\" /><br />";
        strbody+="Age: <input type=text name=\"b\" /><br />";
        strbody += "Location: <input type=text name=\"c\" /><br />";
        strbody+="<input type=submit value=submit id=btnSend/><input type=reset />";
        
        strbody+="</form>";
        strbody += "</html>";
        strbody += "</body>";
        return strbody;

    }
    protected void btnSendMail_Click(object sender, EventArgs e)
    {
       
        try
        {
            string body;
            body = mailbody();
            MailMessage msg = new MailMessage();
            msg.To.Add(new MailAddress(txtEmail.Text)); //To Email address
            msg.From = new MailAddress("siddhesh.patankar5189@gmail.com"); //from email address
            msg.Body = body;
            msg.IsBodyHtml = true;
            SmtpClient smp = new SmtpClient();
            smp.Host = "smtp.gmail.com";
            smp.Port = 587;
            smp.UseDefaultCredentials = true;
            smp.Credentials = new System.Net.NetworkCredential("", ""); //userid, password
            smp.EnableSsl = true;
            smp.Send(msg);
            status.InnerText = "Mail Sent";
            //Response.Write("Mail Sent");
        }
        catch (Exception ex)
        {

            status.InnerText = "Mail Not sent";
            //Response.Write(ex.Message);
        }

    }

Processing the data given by receiver and sending the email back

public partial class index : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
    {
      string name;
      string age,location;
      string body;
      name=Request.QueryString["a"];  
      age=Request.QueryString["b"];
      location=Request.QueryString["c"];
      body=mailbody(name,age,location);
      
      ///Response.Write(name + "<br />");
      ///Response.Write(age + "<br />");
      ///Response.Write(location + "<br />");
      try
      {
          
          MailMessage msg = new MailMessage();
          msg.To.Add(new MailAddress("feedbackform123@gmail.com"));   //mail to
          msg.From = new MailAddress("feedbackform123@gmail.com"); //mail from
          msg.Body = body;
          msg.IsBodyHtml = true;
          SmtpClient smp = new SmtpClient();
          smp.Host = "smtp.gmail.com";
          smp.Port = 587;
          smp.UseDefaultCredentials = true;
          smp.Credentials = new System.Net.NetworkCredential("", ""); //userid passwd
          smp.EnableSsl = true;
          smp.Send(msg);
          string sScript = "";
          sScript += "<script language=\"javascript\" type=\"text/javascript\">\n";
          sScript += "alert(' Your Mail has been sent successfully ')\n";
          sScript += "window.close()";
          sScript += "</script>";
          run.InnerHtml = sScript;
          run.Visible = true;
          //Response.Write("Mail Sent");
      }
      catch (Exception ex)
      {
          Response.Write(ex.Message);
      }
      
      
        
    }
    public string mailbody(string name,string age,string location)
    {
       string mbody;
        mbody="";
        mbody+="Name:" + name + "<br />";
        mbody+="Age:" + age + "<br />";
        mbody+="Location:" + location + "<br />";
        return mbody;
    }
    
}

推荐答案

我怀疑您使用gmail地址的事实有时与这项工作有关,而与其他情况无关.您是否考虑过使用Outlook尝试此操作,还是只关心Webmail?我不确定这有多可行,因为在我看来,如今这种东西会被阻止.
I suspect the fact you''re using a gmail address has something to do with this working sometimes and not others. Have you thought to try this with Outlook, or do you only care about webmail ? I''m not sure how doable this is, because it seems to me like the sort of thing that would be blocked, nowadays.


这篇关于电子邮件中的表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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