M
M
Michael2018-12-23 17:22:10
Yii
Michael, 2018-12-23 17:22:10

Resending the document to the mail, why?

Hello everybody! There is a GridView table, a separate button is written to send an automatically generated pdf document to the specified mail. The document arrives in the mail, there are no problems, but it happens that no one presses the send button, and the same document comes to the user again a week later, why this happens I can’t understand, please help.
Code in controller:

public function actionPdf($id)
{
    $model = $this->findModel($id);
    $content = Yii::$app->view->renderFile('@app/views/order/_forma.php', ['model'=>$model]);

    $pdf = new Pdf([
        'mode' => Pdf::MODE_UTF8,
        'format' => Pdf::FORMAT_A4,
        'cssFile' => '@vendor/kartik-v/yii2-mpdf/assets/kv-mpdf-bootstrap.css',
        'orientation' => Pdf::ORIENT_LANDSCAPE, 
        'destination' => Pdf::DEST_BROWSER,
        'content' => $content,
        'options' => ['title' => 'Портал'],
    ]);

    // $fileName = 'list' . md5(time()) . '.pdf';
    $fileName = 'list_' . $model->id . '_ot_' . $model->date . '.pdf';
    $filePath = Yii::getAlias('@app/web/upload/documents/rctp/pdf/' . $fileName);

    $attachment =  $pdf->output($content, $filePath, Pdf::DEST_FILE);

    $result =  Yii::$app->mailer->compose()
        ->setFrom(['[email protected]' => 'Контора'])
        ->setTo($model->email)
        ->setHtmlBody('Текст')
        ->setSubject('Перечень оборудования #' . $model->id . ' от ' . $model->date)
        ->attach($filePath)
        ->send();

    unlink($filePath);

    return $this->redirect(Yii::$app->request->referrer);
}

Submit button code
[
    'label' => '',
    'value' => function($data){
        if($data['email'] == true){
            return Html::a(
            	'<span>', 
            	Url::to(['order/pdf', 'id' => $data->id]), 
            	[
            		'class' => 'glyphicon glyphicon-envelope', 
            		'title' => 'Отправить документ на email ' . $data->email, 
            		'data' => [
                		'confirm' => 'Вы подтверждаете отправку документа пользователю ' . $data->name . ' ' . ($data->email),
                		'method' => 'post',
            		],
            	]);
        }else{
            return '';
        }
    },
    'format' => 'raw',
],

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question