Mantas Poškus
Mantas Poškus

Reputation: 1

Send email to admin shopping cart data

Fist of all sorry for my bad English. I'm using shopping cart plugin for my website (this is only example of the shopping cart) : https://www.jqueryscript.net/layout/Responsive-E-commerce-Shopping-Cart-Plugin-with-jQuery-Shopping-Mall.html

Everything is working fine except sending email to admin (in mail have to by information about sender and all shopping cart data). So please help me i have cartform.php whit this code but i understand it's not enough to send email.

By the way i'm form Lithuania :)

This is picture of cartform.php:

enter image description here

Here it look in index.html

<div class="container-fluid">
        <div class="row">

            <div class="col-sm-9  col-md-10  main" id="main">
                <div class="">
                    <div id="app"></div>
                </div>

                <div class="row">
                    <ul id="default-item-list" class="col-md-12"></ul>
                </div>

                <div class="row">
                    <div id="detail"></div>
                </div>
            </div>

      <h2 id="basket-message" class="text-right">Jūs turite <span id="basket">0</span> prekes krepšelyje</h2>

            <div class="col-sm-3 col-sm-offset-3 col-md-2 col-md-offset-2 sidebar" id="sidebar">
                <table id="shopping-cart" class="table table-responsive">
                    <tbody id="shopping-list"></tbody>
                    <tfoot>
                        <tr>
                            <td colspan="4" id="total">€ 0.00</td>
                        </tr>
                    </tfoot>
                </table>
                <button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal" id="showForm">Užsakyti</a>
            </div>
        </div>
     </div>


  <!-- Modal -->
  <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" data-backdrop="static"
   data-keyboard="false">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">

          <h2 class="modal-title" id="myModalLabel">Užsakymo patvirtinimas</h2>
        </div>
        <div class="modal-body">

          <form id="sendMail" action="contactform.php" method="post">
              <p>Suveskite savo duomenis, o tekso laukelyje įveskite adresą, kuriuo norite gauti prekes bei kitą svarbią informacija.</p>
            <fieldset>
              <div class="row">
                <div class="form-group col-sm-12">
                  <label for="name">Vardas:<span>*</span></label>
                  <input type="text" name="name" class="form-control " placeholder="Jūsų vardas:" id="name" required="">
                  <div class="alert alert-danger">Laukelis tuščias arba toks negalimas</div>
                </div>
              </div>

              <div class="row">
                <div class="form-group col-sm-12">
                  <label for="email">El. paštas:<span>*</span></label>
                  <input type="email" name="mail" class="form-control " placeholder="Jūsų el. paštas:" id="email" required="">
                  <div class="alert alert-danger">Laukelis tuščias arba toks negalimas</div>
                </div>
              </div>

              <div class="row">
                <div class="form-group col-sm-12">
                  <label for="message">Adresas ir kita:<span>*</span></label>
                  <textarea class="form-control" name="message" placeholder="Įveskite tekstą:" id="message" required=""></textarea>
                  <div class="alert alert-danger">Įveskite adresą, kuriuo norite gauti prekes ir kitą svarbią informacija</div>
                  <span class="form-info"><span class="required">*</span>Įveskite adresą bei kitą svarbią informacija</span>
                </div>
              </div>
            </fieldset>
          </form>

          <div id="thanks">
            <h1>Užsakymas įšsiųstas</h1>
            <p>Patvirtinus užsakymą su Jumis bus susisiekta dėl apmokėjimo.</p>
            <a class="btn btn-default" onclick="location.reload();">Uždaryti</a>
          </div>

        </main>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">Išeiti</button>
          <button type="submit" class="btn btn-danger" id="sendMailButton">Užsakyti</button>
        </div>
      </div>
    </div>
  </div>

Edit 1

but if I set $from = "[email protected]"; it always be writing it send from this email or I dont understand something? Sorry I'm new in this it. I'm student and i have create website with shopping cart who will send email to admin with shopping cart data.

Upvotes: 0

Views: 357

Answers (1)

NightOwl
NightOwl

Reputation: 359

Your code doesn't seems to have basic PHP mail requirements. Refer the following code:

$from = "[email protected]";
$to   = "[email protected]";

$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= "From:<$from>" . "\r\nReply-to: $from";
// the message
$msg = "Mail content";

// send email
$mail_send = @mail($to,"My subject",$msg,$headers);
if($mail_send)
   echo "success";
else
   echo "error";

Upvotes: 1

Related Questions