Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jagdishabhiandroid's avatar

How to make mail dynamic with data from table and send invoice mail to customer

I am trying to mail the invoice to the customer with there ordered data but unable to send data in a loop to view using dompdf i want to make item list dynamic here is my code

Controller:

 $restdetails = res_details::first();

   $data = ['resname' => $restdetails->resname];
   $varients = ['varient_name' => $restdetails->resname];
   $extras = ['extra_name' => $restdetails->resname];
 
   view()->share('admin.pdf.invoice',compact('data', 'extras', 'varients'));

    Mail::send(['html'=>'admin.pdf.invoice'], $data, function($message) use ($data,$extras,$varients) {

        $pdf = PDF::loadView('admin.pdf.invoice',compact('data', 'extras', 'varients'));

        $message->to('[email protected]','John Smith')->subject('Send Mail from Laravel');

        $message->attachData($pdf->output(), 'filename.pdf');

    });
   echo 'Email was sent!';

and my view is :

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Aloha!</title>

<style type="text/css">
    * {
        font-family: Verdana, Arial, sans-serif;
    }
    table{
        font-size: x-small;
    }
    tfoot tr td{
        font-weight: bold;
        font-size: x-small;
    }
    .gray {
        background-color: lightgray
    }
</style>

</head>
<body>

  <table width="100%">
    <tr>
        <td valign="top"><img src="{{asset('/public/logo.png')}}" alt="" width="150"/></td>
        <td align="right">
            <h3>INVOICE</h3>
            <pre>
              {{$data->resname}}
                
            </pre>
        </td>
    </tr>

  </table>

  <table width="100%">
    <tr>
        <td><strong>From:</strong>sdsdds</td>
        <td><strong>To:</strong> Linblum - Barrio Comercial</td>
    </tr>

  </table>

  <br/>

  <table width="100%">
    <thead style="background-color: lightgray;">
      <tr>
        <th>#</th>
        <th>Description</th>
        <th>Quantity</th>
        <th>Unit Price $</th>
        <th>Total $</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <th scope="row">1</th>
        <td>Playstation IV - Black</td>
        <td align="right">1</td>
        <td align="right">1400.00</td>
        <td align="right">1400.00</td>
      </tr>
      <tr>
          <th scope="row">1</th>
          <td>Metal Gear Solid - Phantom</td>
          <td align="right">1</td>
          <td align="right">105.00</td>
          <td align="right">105.00</td>
      </tr>
      <tr>
          <th scope="row">1</th>
          <td>Final Fantasy XV - Game</td>
          <td align="right">1</td>
          <td align="right">130.00</td>
          <td align="right">130.00</td>
      </tr>
    </tbody>

    <tfoot>
        <tr>
            <td colspan="3"></td>
            <td align="right">Subtotal $</td>
            <td align="right">1635.00</td>
        </tr>
        <tr>
            <td colspan="3"></td>
            <td align="right">Tax $</td>
            <td align="right">294.3</td>
        </tr>
        <tr>
            <td colspan="3"></td>
            <td align="right">Total $</td>
            <td align="right" class="gray">$ 1929.3</td>
        </tr>
    </tfoot>
  </table>

</body>
</html>



0 likes
1 reply
jagdishabhiandroid's avatar

I want to perform all the calculation on that view so it will be dynamic for everyone plz help me out

Please or to participate in this conversation.