Diluka Posted March 17, 2018 Share Posted March 17, 2018 (edited) Hi I have a product inquiry form that I have hook on product page and php mail handler in the server. Its working fine for me sending email to my shop email and customer for confirmation of inquiry. It send Name, Phone, Email, Massage and Page URL which has product id. Now I need to improve it to preload Customer Name and Customer Email when a customer is logged. My form is not loading those info and work indipendantly from all other. I am new to coding, if someone can show me what should be modified and where it should be, is great. Thanks in advance. HTML Form <div id="content-wrapper" class="left-column col-xs-12 col-sm-12 col-md-8 col-lg-9"> <section id="main"> <section id="content" class="page-content card card-block"> <section class="contact-form"> <form action="http://www.mydomain.com/form/contact-form-handler.php" method="post" enctype="multipart/form-data"> <div class="form-group row"> <div class="col-md-9 col-md-offset-3"> <h3><b>Contact us</b></h3> </div> </div> <p> <div class="form-group row"> <label class="col-md-3 form-control-label">Your Name</label> <div class="col-md-6"> <input class="form-control" name="name" type="text" value="" placeholder="Your Name" > </div> </div> </p> <p> <div class="form-group row"> <label class="col-md-3 form-control-label">Your Phone Number</label> <div class="col-md-6"> <input class="form-control" name="phone" type="text" value="" placeholder="Your phone with country code" > </div> </div> </p> <p> <div class="form-group row"> <label class="col-md-3 form-control-label">Your Email Address</label> <div class="col-md-6"> <input class="form-control" name="email" type="email" value="" placeholder="your@email.com" > </div> </div> </p> <p> <label for='message'>Message:</label> <br> <textarea class="form-control" name="message" placeholder="How can we help?" rows="3" ></textarea> </p> <script type="text/javascript"> window.onload=function() {document.getElementById('pageurl').value = window.location.href;} </script> <input type="hidden" id="pageurl" name="pageurl" value="pageurl" /> <footer class="form-footer text-sm-right"> <input class="btn btn-primary" type="submit" value="Submit"> </footer> </form> </section> </section> </div> PHP Mail Handler <?php $errors = ''; $myemail = 'shopemail@gmail.com';//<-----Shop email address here. if(empty($_POST['name']) || empty($_POST['phone']) || empty($_POST['email']) || empty($_POST['message']) || empty($_POST['pageurl'])) { $errors .= "\n Error: all fields are required"; } $name = $_POST['name']; $phone = $_POST['phone']; $email_address = $_POST['email']; $message = $_POST['message']; $pageurl = $_POST['pageurl']; if (!preg_match( "/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i", $email_address)) { $errors .= "\n Error: Invalid email address"; } if( empty($errors)) { $to = $myemail; $email_subject = "Shop Product Inquiry: $name"; $email_body = "<html><body><table>"; $email_body .='<img src="http://www.mydomain.com/productinquiry/pii.jpg" alt="Product Inquiry" />'; $email_body .="<h1><strong>You have received a new message!!!</strong></h1>"; $email_body .="<h2><strong>Inquiry details:</strong></h2> <tr><td><strong>Name:</strong></td><td>$name</td></tr> <tr><td><strong>Phone:</strong></td><td>$phone</td></tr> <tr><td><strong>Email:</strong></td><td>$email_address</td></tr> <tr><td><strong>Message:</strong></td><td>$message</td></tr> <tr><td><strong>Product ID:</strong></td><td>$pageurl</td></tr>"; $email_body .= "</table></body></html> $email_body1 = "<html><body><table>"; $email_body .='<img src="http://www.mydomain.com/productinquiry/pii.jpg" alt="Product Inquiry" />'; $email_body1 .= "<strong>Thank you for your inquiry, we will be in touch soon. You can reply to this email for direct contact. "."Inquiry details:</strong> <tr><td><strong>Name:</strong></td><td>$name</td></tr> <tr><td><strong>Phone:</strong></td><td>$phone</td></tr> <tr><td><strong>Email:</strong></td><td>$email_address</td></tr> <tr><td><strong>Message:</strong></td><td>$message</td></tr> <tr><td><strong>Product ID:</strong></td><td>$pageurl</td></tr>"; $email_body1 .= "</table></body></html> $headers = "From: $myemail\n"; $headers .= "Reply-To: $email_address"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; $headers1 = "From: $myemail\n"; $headers1 .= "Reply-To: $myemail"; $headers1 .= "MIME-Version: 1.0\r\n"; $headers1 .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; mail($to,$email_subject,$email_body,$headers); mail($email_address, $email_subject , $email_body1 , $headers1); //redirect to the 'thank you' page header("Location: $pageurl"); } ?> Edited March 17, 2018 by Diluka (see edit history) Link to comment Share on other sites More sharing options...
sacerro Posted March 17, 2018 Share Posted March 17, 2018 (edited) You can use Context object. In context you have customer object. In customer you can get name, surname and all user data. Pass this needed fields to smarty and use in your tpl. You only need to check if Customer is logged. You can use $this->context or Context::getInstance() (depend if is template or is module). Hope this help you Edited March 17, 2018 by sacerro (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now