表格邮件不支持拉丁字符

时间:2012-10-22 17:43:32

标签: php forms utf-8

我无法收到我(图片)上传表单发送的电子邮件,以支持拉丁字符。

  $headers .= "\nMIME-Version: 1.0\n" .
                  "Content-Type: multipart/mixed\n" .
                  " boundary=\"{$mime_boundary}\"";


      $message ="This is a multi-part message in MIME format.\n\n";
      $message.="--{$mime_boundary}\n";
      $message.="Content-Type: text/html; charset=utf-8\n";
      $message.="Content-Transfer-Encoding: 7bit\n\n";

有什么想法吗?

对于精简内容感到抱歉,这会更有帮助吗?

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


    $headers = "From: $emailfrom";


      $semi_rand = md5(time());
      $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";



      $headers .= "\nMIME-Version: 1.0\n" .
                  "Content-Type: multipart/mixed\n" .
                  " boundary=\"{$mime_boundary}\"";




      $subject='Presentación de la fotografía';

      $message ="This is a multi-part message in MIME format.\n\n";
      $message.="--{$mime_boundary}\n";
      $message.="Content-Type: text/html; charset=utf-8\n";
      $message.="Content-Transfer-Encoding: 7bit\n\n";
      $message.="".$namefrom." nos envía este foto.<br />\n\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));


      $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";
    }


    $envs = array("HTTP_USER_AGENT", "REMOTE_ADDR", "REMOTE_HOST");
    foreach ($envs as $env)
    $message .= "$env: $_SERVER[$env]\n";

    if(!mail($to,$subject,$message,$headers)) {
        exit("Disculpa se ha producido un error. Inténtalo de nuevo. Gracias<");
    } else {
        echo '<div id="formfeedback">'. $thanksmessage .'</div>';
        unset($_SESSION['myForm']);
        print_form();

    }

奇怪的是,当我在我的Mac上收到我的测试邮件时,我得到了无效的字符,但我的iPhone显示正确。

2 个答案:

答案 0 :(得分:0)

使用charset ISO-8859-1。它支持西欧,拉丁语-1。 UTF-8是ASCII兼容的多字节8位Unicode。

答案 1 :(得分:0)

以下内容

格式为:$message.="Content-Type: text/html; charset=utf-8\n"; 在html中:<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">

我实际上唯一改变的是(在html元中)UTF-8为大写字母。