A
A
Alice2020-05-08 21:24:44
PHP
Alice, 2020-05-08 21:24:44

How to pass data to php include file?

The mail.php file is the form handler. The data goes into it in the $_POST array. Based on this data, I need to generate an e-mail template which I connect with this line

$mail->msgHTML(file_get_contents('../master/simple.php'), __DIR__);

Question: How do I pass the data from the POST array to the simple.php include file to form an e-mail?
mail.php

<?php
require 'PHPMailer.php';
require 'Exception.php';
require 'SMTP.php';

$mail = new PHPMailer(true);

try {

$mail->isSMTP();
$mail->Host = 'smtp.yandex.ru';
$mail->SMTPAuth = true;
$mail->Username = '[email protected]';
$mail->Password = 'password';
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true)
);

$mail->setFrom('[email protected]', 'Mailer');

$mail->addAddress('[email protected]', 'User');

$mail->isHTML(true);
$mail->Subject = 'Заказ';
$mail->msgHTML(file_get_contents('../master/simple.php'), __DIR__);
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

$mail->send();
echo 'Заказ успешно оформлен, с вами свяжутся в ближайшее время.';
} catch (Exception $e) {
$mail->setLanguage('ru', 'language/');
echo "Заказ не может быть оформлен: {$mail->ErrorInfo}";
}

simple.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="ru">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="viewport" content="width=device-width"/>

    <style type="text/css">

        img {
            max-width: 100%;
            margin: 0 auto;
            display: block;
        }

        body,
        .body-wrap {
            width: 100% !important;
            height: 100%;
            background: #efefef;
            -webkit-font-smoothing: antialiased;
            -webkit-text-size-adjust: none;
        }

        a {
            color: #71bc37;
            text-decoration: none;
        }

    </style>
</head>
<body>
<table class="body-wrap">
    <tr>
        <td class="container">
            <!-- Message start -->
            <table>
                <tr>
                    <td class="content">
                        <h2>Новый заказ</h2>
                        <p>Kielbasa venison ball tip shankle.</p>
                        <table>
                            <tr>
                                <td align="center">
                                    <p>
                                        <a href="#" class="button"><?php echo $product['name']; ?></a>
                                    </p>
                                </td>
                            </tr>
                        </table>
                        <p>By the way, if you're wondering where you can find more of this fine meaty filler, visit <a
                                    href="http://baconipsum.com">Bacon Ipsum</a>.</p>
                        <p><em>– Mr. Pen</em></p>
                    </td>
                </tr>
            </table>
        </td>
    </tr>

</table>
</body>
</html>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
galaxy, 2020-05-08
@blonde_13

It's hard to advise without seeing simple.php, but most likely something like this:

ob_start();
include('../master/simple.php');
$mail->msgHTML(ob_get_clean());

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question