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 电子邮件。使用PHPMailerSwiftmailer,它们几乎可以为您完成所有工作。您可以用大约 5 或 6 行代码替换整个脚本。

最重要的是,它们会为您提供比可悲愚蠢的 mail() 函数更好的错误消息/诊断。

此外,Geekmail PHP 库使向电子邮件添加附件变得容易

于 2013-01-14T12:04:11.157 回答
0

what is "mysql_error"? i think the correct syntax for you die statement is

die(mysql_error());

or

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