0

嗨,我有这段代码:

    <?php
$name = $_POST['name']; 
$email = $_POST['email'];
$phone = $_POST['phone'];
$company = $_POST['company'];
$phone = $_POST['phone'];
$address = $_POST['address'];
$address2 = $_POST['address1'];
$zip = $_POST['zip'];
$delivery = $_POST['delivery'];
$represents = $_POST['represent'];
$npairs = $_POST['npairs'];
$cuff = $_POST['cuff'];
$notes = $_POST['Text'];

    // Headers
        $headers = "From: $email";

        // create a boundary string. It must be unique
          $semi_rand = md5(time());
          $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

          // Add the headers for a file attachment
          $headers .= "\nMIME-Version: 1.0\n" .
                      "Content-Type: multipart/mixed;\n" .
                      " boundary=\"{$mime_boundary}\"";


        $fileatt      = $_FILES['artwork1']['tmp_name'];
        $fileatt_type = $_FILES['artwork1']['type'];
        $fileatt_name = $_FILES['artwork1']['name'];


$todayis = date("l, F j, Y, g:i a") ;

$attn = $attn ; 
$subject = $attn; 

$notes = stripcslashes($notes);
$interested = stripcslashes($interested);

$message = " $todayis [EST] \n
From: $name \n
e-mail: $email \n
Phone: $phone \n
Company: $company \n
Phone: $phone\n
Address: $Address\n
State / Providence:  $address2\n 
Zip code: $zip
Country: $delivery

Represents: $represents
Number of pairs: $npairs
Style of Socks: $cuff



Message: $notes \n 
";

        if (is_uploaded_file($fileatt)) {
          // Read the file to be attached ('rb' = read binary)
          $file = fopen($fileatt,'rb');
          $data = fread($file,filesize($fileatt));
          fclose($file);

          // Base64 encode the file data
          $data = chunk_split(base64_encode($data));

          // Add file attachment to the message
          $message .= "--{$mime_boundary}\n" .
                      "Content-Type: {$fileatt_type};\n" .
                      " name=\"{$fileatt_name}\"\n" .
                      //"Content-Disposition: attachment;\n" .
                      //" filename=\"{$fileatt_name}\"\n" .
                      "Content-Transfer-Encoding: base64\n\n" .
                      $data . "\n\n" .
                      "--{$mime_boundary}--\n";
        }





 );

mail("my@mail.com", 'My tittle', $message,$headers);

?>

但是由于某种原因,当我在邮件中收到附件时,没有任何信息,我收到“无名”。没有扩展或任何东西..有人知道我在哪里做错了吗?

4

2 回答 2

1
    $message = " {$todayis} [EST] \n
From: {$name} \n
e-mail: {$email} \n
Phone: {$phone} \n
Company: {$company} \n
Phone: {$phone}\n
Address: {$Address}\n
State / Providence:  {$address2}\n 
Zip code: {$zip}
Country: {$delivery}

Represents: {$represents}
Number of pairs: {$npairs}
Style of Socks: {$cuff}



Message: {$notes} \n 
";
于 2012-07-23T15:15:32.120 回答
1

在 $message 部分将变量放入 {} 括号?由于需要将它们放入字符串中,您还可以将字符串与变量连接起来。

于 2012-07-23T15:02:40.443 回答