PHP, Swift-mailer problem

前端 未结 4 565
灰色年华
灰色年华 2020-12-07 02:51

When I click submit button on my contact page, trying to submit a form that uses swift-mailer, I get this:

Warning: fopen(uploads/) [function.fopen]

相关标签:
4条回答
  • 2020-12-07 03:02

    This works for me:

    Controller.php

    $mail = Yii::$app->mailer->compose('@app/mail/embed-mail',
    [
         'term' => Url::to('@webroot/images/term.png'),
         'logo' => Url::to('@webroot/images/LOGO.jpg')
    ]
    

    And embed-mail.php

    <img src="<?= $message->embed($terminal); ?>"/>
    <img src="<?= $message->embed($logo); ?>"/>
    

    I hope this works for you

    0 讨论(0)
  • 2020-12-07 03:02

    From the error messages, it seems as if you were specifying a directory where a file path is needed. Maybe because of a missing variable that is supposed to contain the file name.

    0 讨论(0)
  • 2020-12-07 03:11

    You need to supply the full path to uploads not a realtive path because that is going to be interpreted as relative to class file that tries to open your attachment.

    Try using realpath before passing the path to Swift.

    $path = realpath('uploads/');

    0 讨论(0)
  • 2020-12-07 03:16

    Thank you all for your help! The problem was my absentmindedness - I forgot to create 'upload' directory there. Now it works fine. Thank you!

    0 讨论(0)
提交回复
热议问题