0

Lack of my symfony knowledge bottlenecking me. i searched on web but not exactly solution found yet so here i am. How to pass $parameters to sendmail function rendering $data not working i think but it worked on to see but calling it ajax(using ajax is not cause error but render) is not working i guess.

**
* some route settings
**
function index(){
    ...
                $parameters = array(
                    'feedtitle' => $feedback->getTitle(),
                    'feedtype' => $feedback->getFeedtype(),
                    'feeddesc' => $feedback->getDescription(),
                    'feedpublish' => $feedback->getPublishedAt(),
                    'feedauthor' => $user->getFirstName() . ' ' . $user->getLastName(),
                );

                $this->sendEmail($parameters, $mailer, "[email protected]", '[email protected]');
}
function sendmail($data, $mailer, $from, $to){
    ...
    $message = (new \Swift_Message('Хэрэглэгчдийн санал'))
            ->setFrom($from)
            ->setTo($to)
            ->setBody(
                $this->renderView(
                // templates/emails/issue.html.twig
                    'email/issue.html.twig',
                    ['data' => $data]  <-- not working
                ),
                'text/html'
            )

            ...
}

here is issue.html.twig

<table style="width:100%; border-collapse:collapse;font-family: sans-serif; text-align: left;">
    <thead>
        <tr style="font-size:14px;">
            <th style="border:1px solid #3d3d3d">Name</th>
            <th style="border:1px solid #3d3d3d">Caption</th>
            <th style="border:1px solid #3d3d3d">Type</th>
            <th style="border:1px solid #3d3d3d">Description</th>
            <th style="border:1px solid #3d3d3d">Date</th>
        </tr>
    </thead>
    <tbody>
        <tr style="font-size:12px;">
            <td style="border:1px solid #3d3d3d">{{ data.feedauthor }}</td>
            <td style="border:1px solid #3d3d3d">{{ data.feedtitle }}</td>
            <td style="border:1px solid #3d3d3d">{{ data.feedtype }}</td>
            <td style="border:1px solid #3d3d3d">{{ data.feeddesc }}</td>
            <td style="border:1px solid #3d3d3d">{{ data.feedpublish }}</td>
        </tr>
    </tbody>
</table>
4
  • 1
    <td style="border:1px solid #3d3d3d">{{ feedauthor }}</td> etc Commented Nov 5, 2019 at 8:49
  • @u_mulder i edited my question i post tested one Commented Nov 5, 2019 at 8:57
  • Did you try to add a dump of data ? Commented Nov 5, 2019 at 9:17
  • @GrenierJ yeah i dumped its working array do you wanna see array:5 [ "feedtitle" => "1231231" "feedtype" => "request" "feeddesc" => "asdasdad" "feedpublish" => DateTime @1572947913 {#1476 date: 2019-11-05 09:58:33.288874 UTC (+00:00) } "feedauthor" => "Bat Adminshuudee" ] Commented Nov 5, 2019 at 10:01

2 Answers 2

1

You need to change parameter like this:

function sendmail($data, $mailer, $from, $to){
    ...
    $message = (new \Swift_Message('Хэрэглэгчдийн санал'))
            ->setFrom($from)
            ->setTo($to)
            ->setBody(
                $this->renderView(
                // templates/emails/issue.html.twig
                    'email/issue.html.twig',
                    ['data' => $data] 
                ),
                'text/html'
            )

            ...
}
Sign up to request clarification or add additional context in comments.

2 Comments

Or not prefix your twig variables by data.
oh sorry i edited actually i posted wrong one i coding like this ['data' => $data] i reedited that means its like your answer on my coding
0

and i changed i changed my controller

             $parameters = array(
                    'feedtitle' => $feedback->getTitle(),
                    'feedtype' => $feedback->getFeedtype(),
                    'feeddesc' => $feedback->getDescription(),
                    'feedpublish' => $feedback->getPublishedAt()->format('Y-m-d H:i:s'), <-- forget to toString() date format
                    'feedauthor' => $user->getFirstName() . ' ' . $user->getLastName(),
                );

and its worked

Problem is its causing datetime to print out on twig i forget to convert and its working know

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.