swiftmailer and email form with attachment - beginner

后端 未结 3 427
我在风中等你
我在风中等你 2020-12-31 06:39

As always here is the place where I have learned a lot. And I have now a new things to learn:

I have a html form:

F         


        
3条回答
  •  春和景丽
    2020-12-31 07:05

    There's a simple way to do this, here you go:

    $message->attach(
    Swift_Attachment::fromPath('/path/to/image.jpg')->setFilename('myfilename.jpg')
    );
    

    That's one way SwiftMail can do this, now just the /tmp file, and turn the above into the following:

    Assuming: fileatt is the variable for the $_FILE, ['tmp_name'] actually is the tmp file that PHP creates from the form upload.

    $message->attach(
    Swift_Attachment::fromPath($_FILES['fileatt']['tmp_name'])->setFilename($_FILES['fileatt']['name'])
    );
    

    More information on SwiftMail Attachments can be found on this docs page

    More information on $_FILES can be found here on w3schools, despite I don't like w3schools, this page is solid.

提交回复
热议问题