【问题标题】:Send a message and upload a file in PHP [duplicate]发送消息并用PHP上传文件[重复]
【发布时间】:2023-03-30 01:07:01
【问题描述】:

我的表单允许用户通过我的电子邮件向我发送消息,但我希望当用户填写表单并选择文件时,文件会上传到服务器并将消息发送给我。我确实做了消息部分,但我无法上传文件。这是我的代码: 索引页:

<form action="mail.php" method="post" enctype='multipart/form-data'>
<input type="text" class="feedback-input" id="firstname" name="firstname"       placeholder="First Name" size="30" required="">
<br/>
<input type="text" class="feedback-input" id="lastname" name="lastname"     placeholder="Last Name" size="30" required="">
<br/>
<input type="email" class="feedback-input" id="title" name="title" placeholder="E-mail"       size="30" required="">
<br/>
<textarea name="message" class="feedback-input" placeholder="What can I help you with?"   style="height: 150px;" required=""></textarea><br/>
<br/>

<input type="file" name="file" id="file" placeholder=" " tabindex="1" required/><br/>
<input type="submit" name="submit" id="Submit" value="Send">

这是 mail.php 文件:

<?php
$firstname = $_POST['firstname'];
$title = $_POST['title'];
$lastname = $_POST['lastname'];
$message = $_POST['message'];
$ip = $_SERVER['REMOTE_ADDR'];
$formcontent=" From: $firstname $lastname \n Email Address: $title \n IP: $ip \n\n                         Description : $message";
$recipient = "myemail@yahoo.com";
$subject = "New Message!!";
$mailheader = "From: $title \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
header("Location: www.mythankyoupage.com");
die();
?>

【问题讨论】:

  • @David 非常感谢,这正是我想要的!

标签: php html forms file upload


【解决方案1】:

我觉得你的文件上传应该基于这个 http://www.w3schools.com/php/php_file_upload.asp 如果您卡在某个地方,请发表评论,我很乐意提供帮助! :)

【讨论】:

    猜你喜欢
    • 2020-03-15
    • 1970-01-01
    • 2018-06-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-18
    • 2013-12-08
    • 2014-07-23
    相关资源
    最近更新 更多