我正在尝试使用swiftmailer发送带附件(上传)的电子邮件:
HTML:
<form enctype="multipart/form-data" class="form-contact email-form">
<input type="text" name="email" placeholder="Your Email Address">
<input type="file" name="fileatt" />
</div>
<input type="submit" class="send-form" value="Send Form">
</form>
PHP:
$mailer = Swift_Mailer::newInstance($transport);
foreach ($_POST as $key => $value)
$messageText .= ucfirst($key).": ".$value."\n\n";
$message = Swift_Message::newInstance('A message')
$message->attach(
Swift_Attachment::fromPath($_FILES['fileatt']['tmp_name'])->setFilename($_FILES['fileatt']['name'])
);
->setFrom(array($_POST['email'] => $_POST['name']))
->setTo(array('xxx' => 'Timo de Vries'))->setBody($messageText);
try{
echo($mailer->send($message));
}
catch(Exception $e){
echo($e->getMessage());
}
exit;
}
但我得到服务器错误。如果我遗漏了这条线
$message->attach(
Swift_Attachment::fromPath($_FILES['fileatt']['tmp_name'])->setFilename($_FILES['fileatt']['name'])
);
邮件发送时出现问题。 有人知道我做错了什么? 感谢