Php 如何使用我的表格将附件文件包含到电子邮件中?

Php 如何使用我的表格将附件文件包含到电子邮件中?,php,javascript,html,forms,email-attachments,Php,Javascript,Html,Forms,Email Attachments,我有一张表格: <form id='contactus' action='send.php' method='post' enctype="multipart/form-data" accept-charset='UTF-8'> <fieldset> <legend>My Form</legend> <table><tbody> <tr valign="top"> <td nowrap="nowrap" s

我有一张表格:

<form id='contactus' action='send.php' method='post' enctype="multipart/form-data" accept-charset='UTF-8'>
<fieldset>
<legend>My Form</legend>
<table><tbody>
<tr valign="top">
<td nowrap="nowrap" style="text-align: right;"><label for='name' >Name: </label></td>
<td><input type='text' name='name' id='name' value=''/></td></tr>
<tr valign="top">
<td nowrap="nowrap" style="text-align: right;"><label for='email' >Email: </label></td>
<td><input type='text' name='email' id='email' value=''/></td></tr>
<tr valign="top">
<td nowrap="nowrap" style="text-align: right;"><label for='link' >Link: </label></td>
<td><input type='text' name='link' id='link' value=''/></td></tr>
<tr valign="top">
<td nowrap="nowrap" style="text-align: right;"><label for='subject' >Subject: </label> 
</td><td><input type='text' name='subject' id='subject' value=''/></td></tr>
<tr valign="top">
<td nowrap="nowrap" style="text-align: right;"><label for='description' >Description: 
</label></td>
<td><textarea rows="10" cols="50" name='description' id='description'></textarea>
</td></tr>
<tr valign="top">
<td nowrap="nowrap" style="text-align: right;"><label for='photo' >Photo: </label></td>
<td><input type="file" name='photo' id='photo' /></td></tr>
</tbody></table>
<td nowrap="nowrap" style="text-align: center;"><input type='submit' value='Send' /></td>
</fieldset>
</form>

我的表格
姓名:
电邮:
链接:
主题:
说明:
照片:
我的'send.php'是

<?php
if(isset($_POST['email'])) {

$email_to = "mymail@gmail.com";
$subject = $_POST['subject'];
$name = $_POST['name'];
$email = $_POST['email'];
$link = $_POST['link'];
$description = $_POST['description'];
$photo = $_POST['photo'];

$email_message .= "Name: ".($name)."\n";
$email_message .= "Email: ".($email)."\n";
$email_message .= "Link: ".($link)."\n";
$email_message .= "Subject: ".($subject)."\n";
$email_message .= "Description: ".($description)."\n";
$email_message .= "Photo: ".($photo)."\n";

// create email headers
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $subject, $email_message);
}
header("Location: thank-you.html");
?>

我的问题是:

1) 一切都很顺利。。除了“照片”,我知道它应该是一个附件。但我不知道怎么做

2) 当我收到邮件时,我怎么能看到这个粗体字

$email\u message.=“名称:”($Name)。“\n”

emp:姓名:约翰

我试过这样做,但没有成功

$email_message .= "<b>Name: </b>".($name)."\n";
$email_message .= "<b>Email: </b>".($email)."\n";
$email_message .= "<b>Link: </b>".($link)."\n";
$email_message .= "<b>Subject: </b>".($subject)."\n";
$email_message .= "<b>Description: </b>".($description)."\n";
$email\u message.=“Name:”($Name)。“\n”;
$email\u message.=“电子邮件:”($email)。“\n”;
$email_message.=“Link:”($Link)。“\n”;
$email_message.=“主题:”($Subject)。“\n”;
$email\u message.=“说明:”($Description)。“\n”;

提前感谢

使用$\u FILES超级全局数组而不是$\u POST来处理文件

 $photo = $_FILES['photo']['name'];
    ...

 $email_message .= "Photo: ".$photo."\n";

必须使用$\u文件指定文件

 $name_of_uploaded_file =
        basename($_FILES['photo']['name']); // get name of file uploaded

    //get the file extension of the file
    $type_of_uploaded_file =
        substr($name_of_uploaded_file,
        strrpos($name_of_uploaded_file, '.') + 1);

    $size_of_uploaded_file =
        $_FILES["photo"]["size"]/1024;//size in KBs

    //copy the temp. uploaded file to uploads folder

    $path_of_uploaded_file = $upload_folder . $name_of_uploaded_file;
    $tmp_path = $_FILES["photo"]["tmp_name"];

    if(is_uploaded_file($tmp_path))
    {
      if(!copy($tmp_path,$path_of_uploaded_file))
      {
        $errors .= '\n error while copying the uploaded file';
      }
    }
首先,我们需要包含这些类的pear库文件

include_once('Mail.php');
include_once('Mail_Mime/mime.php');


$message = new Mail_mime();

$message->setTXTBody($text);

$message->addAttachment($path_of_uploaded_file);

$body = $message->get();

$extraheaders = array("From"=>$from, "Subject"=>$subject,"Reply-To"=>$visitor_email);

$headers = $message->headers($extraheaders);

$mail = Mail::factory("mail");

$mail->send($to, $headers, $body);

@Suzylee我以为你需要文件名。如果需要该文件,请使用
$\u FILES[“file”][“tmp\u name”]
。但是用mail()函数发送附件不是很简单吗。查找附件,请遵循以下步骤