DEDE uses AJAX to submit a Form without refreshing the Form. PHP returns the result $ query = "insert into '{$ diy-> table}' ('id', 'ifcheck' $ addvar) VALUES (NULL, 0 $ addvalue );";
Introduce phpmailer
Add the following code:
/* Send an email */$ addvalue_ary = explode (',', $ addvalue); // because DEDE submits all form data, separate them here. $ Addvar_ary = array (1 => 'name', 2 => 'email ', 3 => 'mobile phone/phone', 4 => 'Website ', 5 => 'message content',); $ text = ''; foreach ($ addvar_ary as $ key => $ value) {$ text. = $ value. ':'. $ addvalue_ary [$ key].'
';} Require ("class. smtp. php "); require (" class. phpmailer. php "); // the downloaded file must be placed in the directory where the file is located. after phpmailer is downloaded, the class. phpmailer. php, class. pop3.php and class. smtp. put php in the/plus directory $ mail = new PHPMailer (); // Create a mail sending class $ mail-> CharSet = "UTF-8"; // specify the character set here! $ Mail-> Encoding = "base64"; $ mail-> WordWrap = 50; // set word wrap $ mail-> IsHTML (true ); // send as HTML $ mail-> IsSMTP (); // use SMTP to send $ mail-> Host = "smtp.163.com"; // your enterprise Post Office domain name, the domain name of your application email address; $ mail-> FromName = "new official website message"; $ mail-> SMTPAuth = true; // enable the SMTP authentication function $ mail-> Username = "XXXX@163.com"; // sender mail user name (please fill in the complete email address), this mailbox is send mail, phpmailer means to use one email address to send emails to another email address. Therefore, you must register an email address $ mail-> Password = "XXXXXXX" in advance; // The sender email Password $ mail-> Port = 25; $ mail-> From = "XXXX@163.com"; // e-mail address $ address = "XXXX@XXX.cn "; // recipient address $ mail-> AddAddress ($ address, "XXX"); // $ mail-> AddAddress ("XXXX@XXX.cn", "XXX "); // recipient address, which can be replaced with any email address in the format of AddAddress ("recipient email", "recipient name") if ($ action = 'post ') {if ($ do = 2) {$ mail_title = "customer message ". date ('Y-m-d H: I: S', time (); $ mail-> Subject = $ mail_title; // email Title $ mail-> Body = $ text; // email content, $ name, $ phone .. wait for the value submitted by the user's front-end, If you do not want to retrieve the number, write a prompt. for example, if the website has a new order, log on to the website and process it in time. // ShowMsg ('Before sending ', 'javascript:;'); if (! $ Mail-> send () {// echo "Fail to send. "; showMsg ('sending failed', 'javascript:; '); // showmsg ('sending failed'); exit ;}// showMsg ('sending successfully ', 'javascript:; '); // echo "email sent successfully"; // you can use showmsg ('sent successfully') to dede '); to test whether the email is sent successfully}/* End send email */if ($ dsql-> ExecuteNoneQuery ($ query) {$ id = $ dsql-> GetLastID (); if ($ diy-> public = 2) {// diy. php? Action = view & diyid = {$ diy-> diyid} & id = $ id $ goto = "diy. php? Action = list & diyid = {$ diy-> diyid} "; $ bkmsg = 'published successfully, now go to the form list page... ';} else {$ goto ='-1'; $ bkmsg = 'the email has been automatically sent to the SPARK staff. please wait for you! ';} Echo "OK"; // showmsg ($ bkmsg, $ goto );}}}
JS code:
Var dataString = 'iname = '+ $ ("# name "). val () + '& email =' + $ ("# email "). val () + '& tel =' + $ ("# tel "). val () + '& website =' + $ ("# website "). val () + '& action = post' +' & diyid = 1 & do = 2 & dede_fields = iname, text; email, text; tel, text; website, text; content, text & dede_fieldshash = 1f6d061a5dd65989abfd887 '; $. ajax ({type: "POST", url: "/plus/diy. php ", data: dataString, success: function (data) {if (data =" OK ") {// Close the mask $ (" # subm Itmask "). fadeOut (500); alert (" submitted successfully! ");} Else {$ (" # submitmask "). fadeOut (500); alert (" error! Please contact us in other ways! ") ;}}); Return false;