swiftmailer和带附件的电子邮件表单 - 初学者
2022-08-31 00:08:27
一如既往,这里是我学到了很多东西的地方。我现在有一个新东西要学:
我有一个html表单:
<tr><td width="16%">File attachment</td><td width="2%">:</td><td><input type="file" name="fileatt" /></td></tr>
和一封邮件.php:
$attachfile=$_POST["fileatt"];
和正确的 swiftmailer 代码来发送电子邮件;
我已经谷歌搜索过,我发现了很多例子 如何发送附件 与存储在网站上的文件,但我想在飞行中做到这一点。因此,当您提交按钮时,它会将其发送给人们,而不是上传文件。
// Create the Transport
$transport = Swift_SmtpTransport::newInstance('mail.server.co.uk', 25)
->setUsername('user')
->setPassword('pass')
;
// Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);
// Create a message
$message = Swift_Message::newInstance($subject)
->setFrom(array('emai@emai.com' => 'name'))
->setBody($html, 'text/html')
;
// Add alternative parts with addPart()
$message->addPart(strip_tags($html), 'text/plain');
// Send the message
$result = $mailer->send($message);
任何人都可以帮我如何进行动态文件上传,请?提前致谢!!!