1

I have a PHP form (Wilio - Survey and Multipurpose Form Wizard) send emails to submitter and admin, it's not connected with a database, my aim is once the user submits his data, the form sends it directly by mail as a word attachment without any more steps.

here is the HTML code

<form id="wrapped" method="POST">
                        <input id="website" name="website" type="text" value="">
                        <div id="middle-wizard">
                            <div class="step">
                                <h3 class="main_question"><strong>1/2</strong>Please fill the below</h3>
                                <div class="form-group">
                                    <input type="text" name="student_name" class="form-control required" placeholder="Student Name" onchange="getVals(this, 'student_name');">
                                </div>
                                <div class="form-group">
                                    <input type="text" name="school_name" class="form-control required" placeholder="School Name" onchange="getVals(this, 'school_name');">
                                </div>
                                <div class="form-group">
                                    <input type="text" name="teacher_name" class="form-control required" placeholder="Teacher Name" onchange="getVals(this, 'teacher_name');">
                                </div>
                                <div class="form-group">
                                    <input type="text" name="class_name" class="form-control required" placeholder="Class" onchange="getVals(this, 'class_name');">
                                </div>
                                <div class="form-group">
                                    <input type="email" name="email" class="form-control required" placeholder="Your Email" onchange="getVals(this, 'email');">
                                </div>
                                <div class="form-group">
                                    <input type="number" name="mobile_number" class="form-control required" placeholder="Mobile Number" onchange="getVals(this, 'mobile_number');">
                                </div>
                            </div>
                            <div class="submit step">
                                <h3 class="main_question"><strong>2/2</strong>Summary</h3>
                                <div class="summary">
                                    <ul>
                                        <li><strong>1</strong>
                                            <h5>Personal Details</h5>
                                            <ul>
                                                <li><label>Student Name</label>: <span id="student_name"></span></li>
                                                <li><label>Mobile Number</label>: <span id="mobile_number"></span></li>
                                                <li><label>Email</label>: <span id="email"></span></li>
                                            </ul>
                                        </li>
                                        <li><strong>2</strong>
                                            <h5>Educational Details</h5>
                                            <ul>
                                                <li><label>School Name</label>: <span id="school_name"></span></li>
                                                <li><label>Teacher Name</label>: <span id="teacher_name"></span></li>
                                                <li><label>Class</label>: <span id="class_name"></span></li>
                                            </ul>
                                        </li>
                                    </ul>
                                </div>
                            </div>


                        </div>

                        <div id="bottom-wizard">
                            <button type="button" name="backward" class="backward">Prev</button>
                            <button type="button" name="forward" class="forward">Next</button>
                            <button type="submit" name="process" class="submit">Submit</button>
                        </div>
                    </form>

and here is the PHP Code

<?php
                    $mail = $_POST['email'];
                    $to = "my-email@my-domain.com";
                    $subject = "Appreciation Certificate";
                    $headers .= 'MIME-Version: 1.0' . "\r\n";
                    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
                    $headers .= "From: Education Council <noreply@my-domain.com>";
                    $message .= '<div style="text-align: center;"><img src="http://www.my-domain.com/testmail/html/img/banner.jpg" alt="Education Council Banner" /></div>';
                    $message .= "<h1 style='text-align: center;'>Appreciation Certificate</h1>";
                    $message .= "\n\n<h2 style='text-align: center;'>World Teachers Day</h2>";
                    $message .= "\n\n<h1 style='text-align: center;'>It's good to appreciate others for their excellence, efforts and giving</h1>";
                    $message .= "\n\n<h1 style='text-align: center;'>Student: </h1>" . $_POST['student_name'];
                    $message .= "\n\n<h1 style='text-align: center;'>School: </h1>" . $_POST['school_name'];
                    $message .= "\n\n<h1 style='text-align: center;'>My thanks and gratitude to my teacher</h1>";
                    $message .= $_POST['teacher_name'];
                    $message .= "\n\n<h1 style='text-align: center;'>On the occasion of World Teachers Day 2019</h1>";
                    $message .= "\n\n<h2 style='text-align: center;'>Hoping for them permanence excellence and giving</h2>";
                    $message .= "\n\n<h2 style='text-align: center;'>The Education Council</h2>";

                    //Receive Variable
                    $sentOk = mail($to,$subject,$message,$headers);

                    //Confirmation page
                    $user = "$mail";
                    $usersubject = "Appreciation Certificate";
                    $userheaders .= 'MIME-Version: 1.0' . "\r\n";
                    $userheaders .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
                    $userheaders .= "From: Education Council <noreply@my-domain.com>\n";
                    $usermessage = "$message"; 
                    mail($user,$usersubject,$usermessage,$userheaders,$headers);
  ?>

hope to find a help.

Cindy Meister
  • 25,071
  • 21
  • 34
  • 43
Triple M
  • 39
  • 1
  • 4
  • What is your issue? – Ajoe Oct 02 '19 at 07:34
  • I need to make the form send the content as an attached word document or pdf instead of sending the content in the email body. – Triple M Oct 02 '19 at 07:38
  • 1
    Possible duplicate of [Create Word Document using PHP in Linux](https://stackoverflow.com/questions/124959/create-word-document-using-php-in-linux) –  Oct 02 '19 at 07:44
  • @ChrisG I have seen many tools in this link but it seems all of them creating a word document to save it locally or sending as attachment manually, but What I am looking for is that once the user submits, the form sends all of its inputs in a word attach, hope you got my point. – Triple M Oct 02 '19 at 08:16
  • Yes, I understand perfectly fine. You need to 1. create the document using one of the methods from the linked question while inserting the POST data 2. attach the created file to the email and send it 3. optionally delete the created file –  Oct 02 '19 at 08:22
  • It looks like that the file should be created and saved first then attach it, Ok it’ll do the required for me, can you please guide me and explain how can I do this on my code. – Triple M Oct 02 '19 at 09:36

0 Answers0