lundi 3 décembre 2018

Laravel simple html form submission - phpmailer

I need to add the following code into phpmailer form submission file. but is not working after i added the code below, PHP Systax Error. I tried many ways with no luck. is a table with some data which need to be included in the PDf file with the submitted form information. Any help or direction will be appreciated.

    <h4><center>Assets Assigned to: </center></h4>

@if ($assets->count() > 0)
    @php
        $counter = 1;
    @endphp
    <table class="table table-striped table-bordered table-hover">
        <thead>
        <tr>

        </tr>
        </thead>
        <thead>
            <tr>
                <th scope="col"  style="width: 1%;">#</th>
                <th scope="col" style="width: 10%;">Asset Tag</th>
                <th scope="col" style="width: 20%;">Category</th>
                <th scope="col" style="width: 30%;">Model</th>
                <th scope="col" style="width: 20%;">Serial</th>
                <th scope="col" style="width: 10%;">Checked Out</th>
            </tr>
        </thead>

    @foreach ($assets as $asset)

        <tr>
            <td><input type="hidden" name="counter" value="validateForm"></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td>
                </td>
        </tr>
            @php
                $counter++
            @endphp
    @endforeach

    </table>
@endif

below is the file where i tried to add the above code with no luck.

<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

//Load Composer's autoloader
require_once __DIR__ . '/vendor/autoload.php';


if(isset($_POST['submit'])){

    //collect form data
    $cdate = $_POST['cdate'];
    $f02 = $_POST['f02'];
    $f03 = $_POST['f03'];
    $f04 = $_POST['f04'];
    $f05 = $_POST['f05'];
    $f06 = $_POST['f06'];


    //check name is set
    //if($name ==''){
       // $error[] = 'Name is required';
    //}

    //check for a valid email address
    //if(!filter_var($email, FILTER_VALIDATE_EMAIL)){
       //  $error[] = 'Please enter a valid email address';
    //}

    //if no errors carry on
    if(!isset($error)){

        //create html of the data
        ob_start();
        ?>


        <h1>Asset Details</h1>

HERE IS WHERE I TRIED TO ADD THE ABOVE CODE.

        <p>Calibration Date: <?php echo $cdate;?></p>
        <p><?php echo $f02;?></p>
        <p>Print Name: <?php echo $f03;?></p>
        <p>signature: <?php echo $f04;?></p>
        <p>Date: <?php echo $f05;?></p>
        <p>Comments: <?php echo $f06;?></p>

        <?php 
        $body = ob_get_clean();

        $body = iconv("UTF-8","UTF-8//IGNORE",$body);


        $mpdf = new \Mpdf\Mpdf(['tempDir' => __DIR__ . '/tmp']);

        //write html to PDF
        $mpdf->WriteHTML($body);


        //output pdf
        //$mpdf->Output('demo.pdf','D');

        $pdfFilePath = "assets-form.pdf";

        //store the file
        $mpdf->Output("./tmp/".$pdfFilePath,'F');
        //save to server
        //$mpdf->Output("mydata.pdf",'F');



    }
}

//if their are errors display them
if(isset($error)){
    foreach($error as $error){
        echo "<p style='color:#ff0000'>$error</p>";
    }
}


$mail = new PHPMailer(true);                              // Passing `true` enables exceptions
try {
    //Server settings
    $mail->SMTPDebug = 0;                                 // Enable verbose debug output
    $mail->isSMTP();                                      // Set mailer to use SMTP
    $mail->Host = 'email-smtp.us-east-1.amazonaws.com';  // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->Username = 'AKI';                 // SMTP username
    $mail->Password = 'AnTD1obNlurxK6JKSx4Z';                           // SMTP password
    $mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 587;                                    // TCP port to connect to

    //Recipients
    $mail->setFrom('noreply@company.com', 'Mailer');
    $mail->addAddress('sysmanager@company.com', 'Joe User');     // Add a recipient


    //Attachments
    $mail->addAttachment('./tmp/assets-form.pdf');         // Add attachments

    //Content
    $mail->isHTML(true);                                  // Set email format to HTML
    $mail->Subject = 'Here is the subject';
    $mail->Body    = 'This is the HTML message body <b>in bold!</b>';
    $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

    $mail->send();
    echo 'Message has been sent';
} catch (Exception $e) {
    echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}

Thanks for the Help



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2FZ17hH
via IFTTT

Aucun commentaire:

Enregistrer un commentaire