Dede submit form form with Ajax without flushing, PHP returns results

Source: Internet
Author: User
Tags word wrap
$query = "INSERT into ' {$diy->table} ' (' id ', ' ifcheck ' $addvar) VALUES (NULL, 0 $addvalue);";


Introduction of Phpmailer


Add the following code:

/* Send mail */$addvalue _ary = Explode (', ', $addvalue);//Because Dede is submitting all form data, it needs to be separated. $addvar _ary = Array (1 = ' salutation ', 2 = ' Email ', 3 = ' mobile/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 the Phpmailer is downloaded, class.phpmailer.php, class.pop3.php and class.smtp.php are placed in/plus directory $mail = new Phpmailer (); Set up 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, you apply for the domain name of the sending mailbox, $mail->fromname= "The" "The->smtpauth"; $mail = true; Enable the SMTP authentication feature $mail->username = "XXXX@163.com"; e-Mail User name (please fill in the full email address), this mailbox is sent mailbox, phpmailer means to use one mailbox to send mail to another mailbox, so early registration good one mailbox $mail->password = "XXXXXXX"; Sender Mailbox Password $mail->port=25; $mail->from = "XXXX@163.com"; email to $address = "XXXX@XXX.cn";//Recipient Address $mail->addaddress ($address, "XXX");//$mail->addaddress (" XXXX@XXX.cn "," XXX ");//recipient address, can be replaced with any email to receive mail, the format is 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; Message title $mail->body = $text; Message content, $name, $phone. such as you take the user front-end submitted by the value, if you do not want to take the number, write a hint, such as, the site has a new order, please log on to the site timely processing. ShowMsg (' Before sending ', ' javascript:; '); if (! $mail->send ()) {//echo "Fail to send."; ShowMsg (' Send failed ', ' javascript:; '); /showmsg (' send failed '); exit;} ShowMsg (' Send success ', ' javascript:; '); /echo "Mail sent successfully"; Dede can use ShowMsg (' send success ') to test whether to send a successful}}/*end send message */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 = ' Publish successfully, now turn to form List page ... '; } else {$goto = '-1 '; $bkmsg = ' Mail has been automatically sent to spark staff, please wait to contact you! '; }echo "OK"; ShowMsg ($bkmsg, $goto); } }}



JS Code:

var datastring = ' iname= ' + $ ("#name"). Val () + ' &email= ' + $ ("#email"). Val () + ' &tel= ' + $ ("#tel"). Val () + ' &web Site= ' + $ ("#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 Matte $ ("# Submitmask "). FadeOut, alert (" Submit success! ");   } else{   $ ("#submitmask"). FadeOut, alert ("Wrong!" Please contact us using other means! ");   }} }); return false;
  • 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.