jquery Ajax e-mail example

Source: Internet
Author: User
Tags mail example

<divclass="form"> <dl> <dt> Your name <small> (required) </small></dt> <dd><input id="name"Type="text"Name="name" class="FormText"require></dd> </dl> <dl> &lt ;d t> Your email <small> (required) </small></dt> <dd><input id="Email"Type="text"Name="Email" class="FormText"require></dd> </dl> <dl> &lt ;d t> Contact Phone </dt> <dd><input id="Phone"Type="text"Name="Phone" class="FormText"></dd> </dl> <dl> <dt> Your thoughts/Comments <small> (required) </small></dt> <dd><textarea id="message"Name="message" class="FormText"></textarea></dd> </dl> <divclass="formbtn"onclick="btnsend ()"> Send Messages </div> <script>//Submit Datafunction Btnsend () {$ ("#txtMsg"). Text (""); varName = $ ("#name"). Val ();//Your name                                varemail = $ ("#email"). Val ();//your e-mail                                varPhone = $ ("#phone"). Val ();//Contact Phone                                varMessage = $ ("#message"). Val ();//What you are thinking                                if(Name.length = =0) {alert ("The salutation cannot be empty!"); return; }                                if(Email.length = =0) {alert ("The mailbox cannot be empty!"); return; }                                varMyreg =/^ ([a-za-z0-9]+[_|\_|\.]?) *[a-za-z0-9][email protected] ([a-za-z0-9]+[_|\_|\.]?) *[a-za-z0-9]+\. [A-za-z] {2,3}$/; if(!myreg.test (email)) {Alert ('Please enter a valid e_mail!'); return; }                                if(Message.length < -) {alert ("opinions cannot be less than 20 characters!"); return; }                                $(". Formbtn"). Val ("is sending, please wait a moment! "); varPostData ="name="+ name +"&email="+ Email +"&phone="+ Phone +"&message="+message; //send processing data to the background$.ajax ({type:"POST",//transfer by postDataType:"text",//data format: JSONUrl:'/email.ashx',//Destination AddressData:postdata, Error:function (XMLHttpRequest , Textstatus, Errorthrown) {alert ("send failed, please contact online customer service! "); }, Success:function (msg) {$ (". Formbtn"). Val ("Send Message");                                    Alert (msg);                            }                                }); }                        </script> </div>

Email.ashx

<%@ WebHandler language="C #"class="Email"%>usingSystem;usingsystem.web;usingKy.common; Public classemail:ihttphandler{ Public voidProcessRequest (HttpContext context) {context. Response.ContentType="Text/plain"; stringName = Kyrequest.getformstring ("name");//Your name        stringemail = kyrequest.getformstring ("Email");//your e-mail        stringPhone = kyrequest.getformstring ("Phone");//Contact Phone        stringMessage = Kyrequest.getformstring ("message");//What you are thinking        if(string. IsNullOrEmpty (name)) {context. Response.Write ("your name is empty"); return; }        if(string. IsNullOrEmpty (email)) {context. Response.Write ("your mailbox is empty"); return; }        if(string. IsNullOrEmpty (Message)) {context. Response.Write ("idea/opinion is empty"); return; }        stringBODY ="Time:"+ DateTime.Now +"<br>ip:"+ kyrequest.getip () +"<br> Address:"+ name +"<br> Email:"+ Email +"<br> Tel:"+ Phone +"<br> Ideas/Comments:"+message; Try        {            stringWwwemail = system.configuration.configurationmanager.appsettings["Wwwemail"].            ToString (); Sendmail.send (Wwwemail,""Mail Assistant" your website received a message"+DateTime.Now, body); Context. Response.Write ("send success, thank you for your support. "); }        Catch{context. Response.Write ("Web. config did not set the receive mailbox, send failed"); }    }     Public BOOLisreusable {Get        {            return false; }    }}

jquery Ajax e-mail example

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.