0

I am creating a website and I was making a appointment form with PHP. It is turning up no errors on the page itself but the email never shows up in the inbox or spam folder of my email. The code I have for it is: `

<form action="contact.php" method="POST">
  <div class="row g-3">
    <div class="col-12 col-sm-6">
      <select name="Doctor" class="form-select bg-light border-0 mb-3" style="height: 55px;">
        <option selected>Select A Doctor</option>
        <option value="PROF DR AZFAR FAROGH">PROF DR AZFAR FAROGH (MEDICINE)</option>
        <option value="PROF DR AJWAD FAROGH">PROF DR AJWAD FAROGH (CARDIAC SURGERY)</option>
        <option value="PROF DR IRFAN KHAN">PROF DR IRFAN KHAN (HEMATOLOGY)</option>
        <option value="DR ASMA HASSAN">DR ASMA HASSAN (PULMONOLOGY)</option>
        <option value="DR USAMA MUNIR">DR USAMA MUNIR (CARDIOLOGY)</option>
        <option value="DR AWAIS NIZAMI">DR AWAIS NIZAMI (CARDIOLOGY)</option>
        <option value="DR SUMYYA ASHRAF">DR SUMYYA ASHRAF (FAMILY PHYSICIAN)</option>
        <option value="DR SABAHAT GUL">DR SABAHAT GUL (CARDIOLOGY)</option>
        <option value="DR MUHAMMAD BURHAN BARKAT">DR MUHAMMAD BURHAN BARKAT (UROLOGY)</option>
        <option value="DR MADIHA AZHAR">DR MADIHA AZHAR (DERMATOLOGY)</option>
        <option value="DR FAHAD QAISAR">DR FAHAD QAISAR (MEDICINE)</option>
        <option value="DR MAHTAB AHMED MUKTAR PATAFI">DR MAHTAB AHMED MUKTAR PATAFI (PHYSIOTHERAPY)</option>
        <option value="DR NASIR MAHMOOD">DR NASIR MAHMOOD (PHYSIOTHERAPY)</option>
        <option value="DR SHEHR BANO">DR SHEHR BANO (PHYSIOTHERAPY)</option>
        <option value="DR MUHAMMAD WASSAM">DR MUHAMMAD WASSAM (PHYSIOTHERAPY)</option>
        <option value="DR SARAH NISAR">DR SARAH NISAR (RADIOLOGY)</option>
        <option value="DR SARAH NISAR">DR AHMAD BILAL (RADIOLOGY)</option>
        <option value="DR ZAFAR JAM">DR ZAFAR JAM (CARDIOLOGY)</option>
        <option value="DR ANWAAR UL HASSAN">DR ANWAAR UL HASSAN (CARDIOLOGY)</option>
        <option value="DR JUNAID AKHTER">DR JUNAID AKHTER (CARDIOLOGY)</option>
        <option value="DR M ZUBAIR AHMAD">DR M ZUBAIR AHMAD (PEDIATRIC SURGERY)</option>
        <option value="DR GOHAR BASHIR">DR GOHAR BASHIR (CARDIAC SURGERY)</option>
      </select>
    </div>
    <div class="col-12 col-sm-6">
      <input type="text" name="Name" class="form-control bg-light border-0" placeholder="Your Name" style="height: 55px;" required>
    </div>
    <div class="col-12 col-sm-6">
      <input type="email" name="Email" class="form-control bg-light border-0" placeholder="Your Email" style="height: 55px;" required>
    </div>
    <div class="col-12 col-sm-6">
      <input type="number" name="Number" class="form-control bg-light border-0" placeholder="Your Phone Number" style="height: 55px;" required>
    </div>
    <div class="col-12 col-sm-6">
      <input type="number" name="CNIC" class="form-control bg-light border-0" placeholder="Your CNIC Number" style="height: 55px;" required>
    </div>
    <div class="col-12 col-sm-6">
      <SELECT name="Gender" class="form-control bg-light border-0" placeholder="Select Your Gender" style="height: 55px;" required>
        <option name="MALE">MALE</option>
        <option name="FEMALE">FEMALE</option>
        <option name="NEUTER">NEUTER</option>
      </SELECT>
    </div>
    <div class="col-12 col-sm-6">
      <input type="number" name="AGE" class="form-control bg-light border-0" placeholder="AGE" style="height: 55px;" required>
    </div>
    <div class="col-12 col-sm-6">
      <div class="date" id="date1" data-target-input="nearest">
        <input type="text" name="Date" class="form-control bg-light border-0 datetimepicker-input" placeholder="Appointment Date" data-target="#date1" data-toggle="datetimepicker" style="height: 55px;" required>
      </div>
    </div>
    <div class="col-12 col-sm-6">
      <input type="text" name="Comments" class="form-control bg-light border-0" placeholder="Additional Comments" style="height: 55px;">
    </div>
    <div class="col-12">
      <button class="btn btn-dark w-100 py-3" type="submit">Make Appointment</button>
    </div>
  </div>
</form>

this is my php file:

<?php
header("Location: ../appointment.html");
if(isset($_POST['Name']) &&
 isset ($_POST['Email']) &&
 isset ($_POST['Doctor']) &&
 isset ($_POST['CNIC']) &&
 isset ($_POST['Number']) &&
 isset ($_POST['Gender']) &&
 isset ($_POST['Age']) &&
 isset ($_POST['Date']) &&
 isset ($_POST['Comments'])) {

 $Name = $_POST['Name'];
 $Email = $_POST['Email'];
 $Doctor = $_POST['Doctor'];
 $CNIC = $_POST['CNIC'];
 $Number = $_POST['Number'];
 $Gender = $_POST['Gender'];
 $Age = $_POST['Age'];
 $Date = $_POST['Date'];
 $Comments = $_POST['Comments'];

  $to = '********@gmail.com';
  $subject = 'Appointment' . $name;
  $body = $message;
  $headers = 'From:' . $email . "\r\n" . "CC: ********@gmail.com";


  if (mail($to, $subject, $body, $headers)) {
    echo 'your message has been sent!';
  } else {
    echo 'There was an error sending your message.';
  }
}
?>

I tired sending just name and message ,it worked but then i tired on this form ,it doesn't worked.

  • `jquery` and `javascript`? Neither is involved. `header("Location: ../appointment.html");` at the top? – brombeer Dec 29 '22 at 07:38
  • Where are `$Name`, `$Email`, `$Doctor` and all the other variables set? – brombeer Dec 29 '22 at 07:39
  • `$_POST['name']` will never be set. `$_POST['email']` will never be set. `$_POST['message']` will never be set. There are no elements with those names – brombeer Dec 29 '22 at 07:42
  • Make sure you use the correct variable/input element names. Redirect _after_ mail has been sent – brombeer Dec 29 '22 at 07:45
  • @brombeer i have corrected this but still not getting mail – Stack Overflow Dec 29 '22 at 07:55
  • Please don't post code in the comments, hard to read. Instead, please [edit] your question and append any changes you made. – brombeer Dec 29 '22 at 07:56
  • Which one of your two `echo`s at the end do you get? `'your message has been sent!'` or `'There was an error sending your message.'`? – brombeer Dec 29 '22 at 08:01
  • @brombeer nothing – Stack Overflow Dec 29 '22 at 08:05
  • `$_POST['Age']` will never be set, pay more attention to how you named your elements – brombeer Dec 29 '22 at 08:05
  • "_Redirect after mail has been sent_" You missed that part. Try moving that redirection to _after_ your mail has been sent – brombeer Dec 29 '22 at 08:06
  • @brombeer NOW I HAVE GOT A ECHO YOUR MESSAGE HAS BEEN SENT,AND ALSO STATUS IS 200 BUT I DIDN'T GOT THE MAIL – Stack Overflow Dec 29 '22 at 08:12
  • Don't post ALLCAPS, it's considered shouting/rude. – brombeer Dec 29 '22 at 08:35
  • Make sure **all** variables you use are actually set. (I can see at least two that aren't. actually three) [How do I get PHP errors to display?](https://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display?rq=1) might help you in debugging. Good luck – brombeer Dec 29 '22 at 08:37
  • Does this answer your question? [PHP mail function doesn't complete sending of e-mail](https://stackoverflow.com/questions/24644436/php-mail-function-doesnt-complete-sending-of-e-mail) – ADyson Dec 29 '22 at 09:51

0 Answers0