現在、下記のindex.hmtlを実行してメールを送信すると、
console.log(result); の結果が、
EMAIL_TO_YOU_SUCCESS<br>EMAIL_TO_QUESTIONER_SUCCESS
となってしまいます。
EMAIL_TO_YOU_SUCCESS
EMAIL_TO_QUESTIONER_SUCCESS
もmail/config.php でテキストを指定していますが、これをindex.htmlのconsole上で表示させるにはどうしたらいいでしょうか?
テキスト形式にはこだわっておらずjson形式でも何でもよいです。
ご教示のほどよろしくお願いいたします。
コードは下記となります。
PHP
1define("EMAIL_TO_YOU_SUCCESS", "Your message has been sent successfully!"); 2define("EMAIL_TO_QUESTIONER_SUCCESS", "Your message has been sent to you successfully!"); 3if (mb_send_mail(YOUR_EMAIL, QUESTIONER_SUBJECT, $to_you_massage, $to_you_header)) { 4 // if the message is sent 5 print EMAIL_TO_YOU_SUCCESS; 6} else { 7 // if the message is failed to send 8 print EMAIL_TO_YOU_FAILED; 9}
jQuery
1$.ajax({ 2 url: $form.attr('action'), 3 type: $form.attr('method'), 4 data: $form.serialize(), 5 timeout: 10000, 6 beforeSend: function(xhr, settings) { 7 // disable the submit button prevending from double sending 8 $submitButton.attr('disabled', true); 9 }, 10 complete: function(xhr, textStatus) { 11 // re-activate the submit button 12 $submitButton.attr('disabled', false); 13 }, 14 15 // after success to send 16 success: function(result, textStatus, xhr) { 17 // initialize values 18 $form[0].reset(); 19 alert('OK'); 20 console.log(result); 21 }, 22 23 // if any sending errors 24 error: function(xhr, textStatus, error) { 25 alert('NG...'); 26 } 27 });
html
1<form method="post" action="./mail/sendmail.php"> 2 3 <div class="form-group"> 4 <label for="fullname">Full Name</label> 5 <input id="fullname" class="form-control" type="text" name="fullname" value=""> 6 </div> 7 8 9 <button type="submit" class="btn btn-primary">Submit</button> 10 </form>
回答1件
あなたの回答
tips
プレビュー