2011-07-26 5 views
0

GoDaddy 서버를 통해 첨부 파일이있는 전자 메일을 보내고 있습니다. 내 Gmail 계정으로 보내면 이메일이 제대로 작동하지만 Outlook에서는 이메일 텍스트가 전혀 표시되지 않습니다. 첨부 파일은 있지만 텍스트는 없습니다.첨부 파일이있는 PHP 이메일을 GoDaddy 서버에 보낼 수 있습니까?

내 hostgator 서버에서 문제없이 작동합니다.

누구나 올바른 방향으로 나를 가리킬 수 있습니까?

<?php 
    function mail_attachment($to, $subject, $message, $from, $file) { 
    // $file should include path and filename 
    $filename = basename($file); 
    $file_size = filesize($file); 
    $content = chunk_split(base64_encode(file_get_contents($file))); 
    $uid = md5(uniqid(time())); 
    $header = "From: ".$from."\r\n" 
     ."MIME-Version: 1.0\r\n" 
     ."Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n" 
     ."This is a multi-part message in MIME format.\r\n" 
     ."--".$uid."\r\n" 
     ."Content-type:text/plain; charset=iso-8859-1\r\n" 
     ."Content-Transfer-Encoding: 7bit\r\n\r\n" 
     .$message."\r\n\r\n" 
     ."--".$uid."\r\n" 
     ."Content-Type: application/octet-stream; name=\"".$filename."\"\r\n" 
     ."Content-Transfer-Encoding: base64\r\n" 
     ."Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n" 
     .$content."\r\n\r\n" 
     ."--".$uid."--"; 
    return mail($to, $subject, "", $header); 
} 

//Settings 
$upload_folder = './data/'; //<-- this folder must be writeable by the script 
$your_email = '[email protected], [email protected]'; 
$errors =''; 

if(isset($_POST['submit'])) 
{ 
    ///------------Do Validations------------- 
if (isset($_FILES['uploadFile'])) 
{ 
} 

//send the email 
if(empty($errors)) 
{ 
    //copy the temp. uploaded file to uploads folder 
    $path_of_uploaded_file = $upload_folder . $name_of_uploaded_file; 
    $tmp_path = $_FILES["uploadFile"]["tmp_name"]; 

    if(is_uploaded_file($tmp_path)) 
    { 
     if(!copy($tmp_path,$path_of_uploaded_file)) 
     { 
      $errors .= '\n error while copying the uploaded file'; 
     } 
    } 

    $user_message = "Contact Information\r\n" . 
     "=======================================\r\n" . 
     "Date: " . $_POST['dateMonth'] . "-" . $_POST['dateDay'] . $_POST['dateYear'] . "\r\n"; 

    } 

    //send the email 
    $to = $your_email; 
    $subject= trim("[SERVICE ORDER]"); 
    $from_email = "[email protected]"; 

    if ($name_of_uploaded_file != "") 
    { 
     $file = "D:\\xxx\\xxx\\html\\data\\" . $name_of_uploaded_file; 
     if (mail_attachment($to, $subject, $user_message, $from_email, $file)) { 
      header("Location: thank-you.html"); 
     } else { 
      echo("<p>Message delivery failed...</p>"); 
     } 
    } else { 
     $headers = 'From: ' . $from_email . "\r\n"; 
     if (mail($to, $subject, $user_message, $headers)) { 
      header("Location: thank-you.html"); 
     } else { 
      echo("<p>Message delivery failed...</p>"); 
     } 
    } 
} 
} 
///////////////////////////Functions///////////////// 
// Function to validate against any email injection attempts 
function IsInjected($str) 
{ 
    $injections = array('(\n+)', 
      '(\r+)', 
      '(\t+)', 
      '(%0A+)', 
      '(%0D+)', 
      '(%08+)', 
      '(%09+)' 
     ); 
$inject = join('|', $injections); 
$inject = "/$inject/i"; 
if(preg_match($inject,$str)) 
    { 
    return true; 
} 
else 
    { 
    return false; 
} 
} 
?> 
+0

첨부 파일없이 GoDaddy 서버에서 작동하도록 이메일을받을 수 있었습니까? 실제로 진행중인 작업을 알기 위해 변수를 제거하거나 활동을 기록해야합니다. 또한 GoDaddy가 전자 메일이 제대로 보내지 못하게하는 제한 사항을 GoDaddy에 확인 했습니까? 마지막으로 두 서버 환경에서 정확히 동일한 코드라고 가정합니다. – Ryan

+0

godaddy를 제외한 동일한 코드는 windows이고 hostgator는 Linux입니다. 첨부 파일이없는 이메일은 정상적으로 작동하고 Gmail은 정상적으로 작동합니다. 그것은 문제가있는 Outlook에만 전자 메일입니다. –

+0

내 직감의 일부가 GoDaddy의 Windows 서버에 문제가 될 수 있다고 말하고 있습니다. 잠재적으로 로컬 SMTP 서버는 메시지를 릴레이 할 수 없습니다. 나는 약 5 년 전에 사용했던 예전의 오래된 Windows 서버와 비슷한 고생을했는데, 이것이 문제였습니다. 나는 사이드 노트에 Marc B에 동의한다. 나는 PHPMailer에 문제가 없다. – Ryan

답변

3

직접 MIME 메시지를 작성하지 마십시오. PHPMailer 또는 Swiftmailer을 사용하십시오. 그들은 훨씬 더 신뢰할 수 있습니다.

+0

ok, 나는 그것들을 살펴볼 것이다. –

+0

BTW, PHP는 똑똑하고 디렉토리 구분자를 변환합니다. 첨부 파일 포함 경로를'D :/xxx/xxx/html/data /'로 만들면 "기울어 진 이쑤시게 증후군"없이 잘 작동합니다. –

+0

글쎄, 잘 알고있다. 나는 PHP 전문가가 아니기 때문에 도움이된다. –

관련 문제