1

我有一个表格:

<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_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";

提前致谢

4

2 回答 2

0

使用 $_FILES 超级全局数组而不是 $_POST 来处理文件。

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

 $email_message .= "Photo: ".$photo."\n";
于 2013-08-10T08:47:46.967 回答
0

您必须使用 $_FILES 指定文件。

 $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);
于 2013-08-10T08:59:52.087 回答