0

メールが添付ファイル付きで送信されていますが、開くことができません。

何が問題ですか、これを解決してください。

<?php

    $file_name=$_FILES['Resume']['name'];
    $file_size=$_FILES['Resume']['size'];
    $file_temp=$_FILES['Resume']['tmp_name'];
    
    $to = 'renu_activa@yahoo.co.in';
    $subject = 'Test email with attachment'; 
    $from=$_POST['First'];
    $random_hash = md5(date('r', time()));
    $headers = "From: $from\r\nReply-To: $from";
    $headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";
    $data = chunk_split(base64_encode(file_get_contents("$file_temp")));
    ob_start(); 
    ?> 
    --PHP-mixed-<?php echo $random_hash; ?>
    Content-Type: multipart/alternative; boundary="PHP-alt-<?php echo $random_hash; ?>"
    
    --PHP-alt-<?php echo $random_hash; ?>  
    Content-Type: text/plain; charset="iso-8859-1" 
    Content-Transfer-Encoding: 7bit
    
    Hello World!!! 
    This is simple text email message. 
    
    --PHP-alt-<?php echo $random_hash; ?>  
    Content-Type: text/html; charset="iso-8859-1" 
    Content-Transfer-Encoding: 7bit
    
    <h2>Hello World!</h2> 
    <p>This is something with <b>HTML</b> formatting.</p> 
    --PHP-mixed-<?php echo $random_hash; ?>
    Content-Type: $file_type; name=$file_name
    Content-Transfer-Encoding: base64
    Content-Disposition: attachment
    
    <?php echo $data; ?>
    --PHP-mixed-<?php echo $random_hash; ?>-- 
    
    <?php 
    //copy current buffer contents into $message variable and delete current output buffer 
    $message = ob_get_clean(); 
    //send the email 
    $mail_sent = @mail( $to, $subject, $message, $headers );//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed" 
    echo $mail_sent ? "Mail sent" : "Mail failed";
            ?>
    
4

2 に答える 2

2

独自の MIME メールを作成しません。PHPMailerまたはSwiftmailerを使用すると、ほぼすべてのことができます。スクリプト全体を約 5 ~ 6 行のコードに置き換えることができます。

そして何よりも、哀れなほど愚かな mail() 関数よりもはるかに優れたエラー メッセージ/診断を提供します。

また、Geekmail PHP ライブラリを使用すると、メールに添付ファイルを簡単に追加できます

于 2013-01-14T12:04:11.157 に答える
0

「mysql_error」とは何ですか? dieステートメントの正しい構文は次のとおりだと思います

die(mysql_error());

また

die($mysql_error);
于 2013-01-14T11:52:46.463 に答える