2011-07-26 24 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には、電子メールが正しく送信されないような制限があるかどうかチェックしましたか?最後に、私は両方のサーバー環境でまったく同じコードであると仮定していますか? – Ryan

+0

godaddyを除くすべてのコードはwindowsで、hostgatorはLinuxです。添付ファイルのないメールは正常に動作し、Gmailのメールはうまく動作します。それは問題を抱えているOutlookへの電子メールだけです。 –

+0

私のやっていることは、GoDaddyのWindowsサーバーで問題が発生している可能性があります。ローカルのSMTPサーバーは、メッセージを中継するために鼻水が流れている可能性があります。私は約5年前に使用した古い古いWindowsサーバーと同様の苦労を経験しており、これが問題でした。私はサイドノートでMarc Bに同意する、私はPHPMailerの問題を自分で持っていない – Ryan

答えて

3

自分でMIMEメッセージを作成しないでください。 PHPMailerまたはSwiftmailerを使用してください。彼らははるかに信頼性が高いです。

+0

大丈夫、私はそれらを見てみましょう。 –

+0

ところで、PHPはスマートで、ディレクトリの区切り文字を変換します。添付ファイルのパスを 'D:/ xxx/xxx/html/data /'にすることができます。これは、「爪楊枝症候群」なしでうまく動作します。 –

+0

まあ、知っておきたいことです。私はPHP専門家ではありませんので、助けてください。 –

関連する問題