【发布时间】:2015-03-04 12:22:48
【问题描述】:
我是 php 新手,我尝试设置一个提交表单。我希望能够上传文件并附加文件并将其与我的消息一起发送。我可以接收所有消息,但没有收到文件。我对消息使用 nl2br 函数。我会很感激任何帮助,谢谢。
【问题讨论】:
标签: php email message attachment
我是 php 新手,我尝试设置一个提交表单。我希望能够上传文件并附加文件并将其与我的消息一起发送。我可以接收所有消息,但没有收到文件。我对消息使用 nl2br 函数。我会很感激任何帮助,谢谢。
【问题讨论】:
标签: php email message attachment
您是否定义了enctype 的表单?您需要这样做才能发送带有表单的文件。
你的某些代码对理解问题有很大帮助,但我猜你没有指定enctype。它应该看起来像这样:
<form action="file.php" method="post" enctype="multipart/form-data">
【讨论】:
您是否在表单中添加了 enctype="multipart/form-data":
<form action="action_page.php" method="POST" enctype="multipart/form-data">
</form>
【讨论】:
在 HTML 中添加 <form> 属性 enctype="multipart/form-data"。
然后,上传文件:<input type="file" name="myfile" />
然后在 PHP 中:
不要使用 PHP mail() 函数直接邮寄,而是使用 PHPMailer。它会让你很容易,自己处理所有这些。您只需调用几个函数就可以了。
这是一个示例:
<?php
require("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "smtp.example.com"; // SMTP server
$mail->From = "from@example.com";
$mail->AddAddress("myfriend@example.net");
$mail->Subject = "An HTML Message";
$mail->Body = "Hello, <b>my friend</b>! \n\n This message uses HTML entities!";
?>
如需完整教程,请访问http://phpmailer.worxware.com/?pg=tutorial
编辑:看这里,查看视频系列:http://bit.ly/1Ekgzel
希望对你有帮助。
【讨论】: