jQuery/PHP mail send the easy way?

后端 未结 1 471
没有蜡笔的小新
没有蜡笔的小新 2021-01-13 23:16

Ok, to make long story short:

JavaScript:

jQuery(\"submit\").click(function() { 

    var address = jQuery(\"#mail\").val();
    var title = jQuery(\         


        
相关标签:
1条回答
  • 2021-01-13 23:56

    You should use Ajax. Its a lot easier. Here is a simple tutorial here on sending mail using PHP, Ajax, & jQuery:

    Send mail using PHP, Ajax and jQuery

    it would look something similar to this:

    var data = "address=" + address + "&title=" + title + "&name=" + name + "&mail=" + mail + "&message=" + message;
    //or however u want to format your data
    
    $.ajax({
         type: "POST",
         url: "sendmail.php",
         data: data,
         success: function(phpReturnResult){
              alert('Success: ' + phpReturnResult);
              jQuery(".email-us").html("<div id='email-sent'><p>Thank you for the message.</p><p>We will reply as soon as possible. PHP Script's return result: " + phpReturnResult + "</p></div>");     
         },
         error: function(errormessage) {
               //you would not show the real error to the user - this is just to see if everything is working
              alert('Sendmail failed possibly php script: ' + errormessage);
         }
    });
    

    Also in your PHP file, you seem to used the mail function twice.

    0 讨论(0)
提交回复
热议问题