このスクリプトはAjaxを使用して呼び出しています。スクリプトの「データベースへの書き込み」部分は正常に実行されますが、何らかの理由で、スクリプトの実行時にsend_receipt()関数が実行されません。
スクリプトは最終的に2つの電子メールを送信するため、電子メールの送信機能はカスタム関数内に含める必要があります。1つは顧客への領収書、もう1つは会社への通知です。したがって、すべてのmail()変数とデータが繰り返されますが、ターゲットの電子メールアドレスが異なり、スクリプトの実行時に両方の関数が呼び出されます。
どんな助けでも大歓迎です。
ありがとう!
アヤックス:
$.ajax({
type: "POST",
url: "selfnormal.php",
data: "fname="+ fname +"& lname="+ lname +"& worktel="+ worktel +"& privtel="+ privtel +"& mobtel="+ mobtel +"& email="+ email +"& workaddress="+ workaddress +"& homeaddress="+ homeaddress +"& level="+ level +"& size="+ size +"& deliv="+ deliv +"& venue="+ venue +"& ioshdate="+ ioshdate +"& isdiscount="+ isdiscount +"& elcas="+ elcas +"& funding="+ funding +"& paytype="+ paytype +"& selfinvoicead="+ selfinvoicead +"& companyname="+ companyname +"& companyaddress="+ companyaddress +"& PO="+ PO +"& tcs="+ tcs +"& finalprice="+ finalprice +"& finalvat="+ finalvat +"& finalfee="+ finalfee +"& finaltotal="+ finaltotal +"& finalmonthly="+ finalmonthly +"& finaladmin="+ finaladmin,
success: function(){
alert ("success");
}
PHP:
<?php
$firstname = htmlspecialchars(trim($_POST['fname']));
$lastname = htmlspecialchars(trim($_POST['lname']));
$worktel = htmlspecialchars(trim($_POST['worktel']));
$privtel = htmlspecialchars(trim($_POST['privtel']));
$mobtel = htmlspecialchars(trim($_POST['mobtel']));
$email = htmlspecialchars(trim($_POST['email']));
$workaddress = htmlspecialchars(trim($_POST['workaddress']));
$homeaddress = htmlspecialchars(trim($_POST['homeaddress']));
$level = htmlspecialchars(trim($_POST['level']));
$size = htmlspecialchars(trim($_POST['size']));
$deliv = htmlspecialchars(trim($_POST['deliv']));
$venue = htmlspecialchars(trim($_POST['venue']));
$ioshdate = htmlspecialchars(trim($_POST['ioshdate']));
$isdiscount = htmlspecialchars(trim($_POST['isdiscount']));
$elcas = htmlspecialchars(trim($_POST['elcas']));
$funding = htmlspecialchars(trim($_POST['funding']));
$paytype = htmlspecialchars(trim($_POST['paytype']));
$selfinvoicead = htmlspecialchars(trim($_POST['selfinvoicead']));
$companyname = htmlspecialchars(trim($_POST['companyname']));
$companyaddress = htmlspecialchars(trim($_POST['companyaddress']));
$po = htmlspecialchars(trim($_POST['PO']));
$tcs = htmlspecialchars(trim($_POST['tcs']));
$courseprice = htmlspecialchars(trim($_POST['finalprice']));
$vat = htmlspecialchars(trim($_POST['finalvat']));
$fee = htmlspecialchars(trim($_POST['finalfee']));
$admin = htmlspecialchars(trim($_POST['finaladmin']));
$total = htmlspecialchars(trim($_POST['finaltotal']));
$monthly = htmlspecialchars(trim($_POST['finalmonthly']));
$dbc = mysqli_connect('xxxx', 'xxxx', 'xxxx', 'xxxx')
or die ('Could not connect to MySQL server.');
$query = "INSERT INTO enrolments (fname, lname, worktel, privtel, mobtel, email, workaddress, homeaddress, level, size, deliv, venue, ioshdate, isdiscount, elcas, funding, paytype, selfinvoicead, companyname, companyaddress, po, tcs, price, VAT, BIFM_Fee, Total, Monthly, adminfee)" .
"VALUES ('$firstname', '$lastname', '$worktel', '$privtel', '$mobtel', '$email', '$workaddress', '$homeaddress', '$level', '$size','$deliv','$venue', '$ioshdate','$isdiscount','$elcas', '$funding', '$paytype','$selfinvoicead','$companyname','$companyaddress','$po','$tcs', '$courseprice', '$vat', '$fee', '$total', '$monthly', '$admin')";
$result = mysqli_query($dbc, $query)
or die ('error querying database');
mysqli_close($dbc);
function send_receipt() {
$to = $email;
$subject = $firstname . ', thank you for enrolling on the ' . $level . ' ' . $size . ' (' . $deliv . ')';
$msg = "Hi $firstname," . PHP_EOL .
PHP_EOL .
"Thanks for enrolling with us. Please find a summary of your enrolment below. We'll be in touch shortly to arrange payment, after which we will send you joining instructions and course details." . PHP_EOL .
PHP_EOL .
"Please be aware that in accordance with UK Legislation, you are legally entitled to a 7 day 'cooling off' period during which you may cancel your course at no cost. After this period, you will be liable for full payment as detailed below." . PHP_EOL .
PHP_EOL .
"Level: $level" . PHP_EOL .
"Scale: $size" . PHP_EOL .
"Delivery Method: $deliv" . PHP_EOL .
"Payment Method: $paytype" . PHP_EOL .
"Course Price: £$courseprice" . PHP_EOL .
"VAT: £$vat" . PHP_EOL .
"ILM/BIFM fee: £$fee" . PHP_EOL .
"Total: £$total" . PHP_EOL .
PHP_EOL .
"We look forward to welcoming you onto the course in the near future." . PHP_EOL .
PHP_EOL .
"Kind regards" . PHP_EOL .
PHP_EOL .
"The Xenon Group staff";
mail ($to, $subject, $msg, 'From: Xenon Group Enrolments');
}
send_receipt();