Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

218
Views
How to add PHPmailer in if else statement and send email through it with a button click?

I have an HTML table and in one of its cells, there is a button to Accept food orders. That data is then checked by another PHP page if it's ok or not and then the data is updated accordingly. Below is the code I used for the HTML table button:

.
.
//codes
.
.

<td>
<center>".$totalamount."</center></td>
   <td><center>".$payment_mode."</center></td>
   <td><center>".$datetime."</center></td>                          
   <td><center><a class='btn btn-primary' href='orderstatus.php?orderid=".$orderid."&orderstatus=Accept'>Accept</center></a>
</td>";?>
</tr>

As you can see the last <td> cell consists of the button which links to another PHP page orderstatus.php. Below is the code for this page:

.
.
//codes
.
.
while($data2 = mysqli_fetch_array($userinfocon))
{
    $username=$data2['username'];
    $useremail=$data2['email'];
}

if($orderstatus=="Accept")
{

//codes

}
if($orderstatus=="InKitchen")
{

//codes

}
if($orderstatus=="Ready")

//codes

Now I want that whenever the status is a particular value or whenever a button is clicked it should send an email to the user using PHPMailer() about their order status.

I tried to do it by adding the PHP mailing code after every if-else statement but that ends up creating a loop that keeps on sending me emails.

I am a beginner in PHP so I am not able to understand what should be done.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!