电子邮件附件未正确发送

时间:2016-08-02 11:49:14

标签: php email

我有一个电子邮件功能,我想发送电子邮件附件3用户上传的不同图片,但问题是我收到3个附件只有1个是正确附加而另外2个没有显示

Google错误[显示此图片时出现问题。 重试...]

html也没有转换它显示电子邮件为

 $fname = $_POST['fname'];
    $surname = $_POST['surname'];
    $email = $_POST['email'];
    $date_of_birth = $_POST['date_of_birth'];
    $height = $_POST['height'];
    $age = $_POST['age'];
    $gender = $_POST['gender'];
    $address = $_POST['address'];
    $instagram = $_POST['instagram'];
    $facebook = $_POST['facebook'];

    $path = "./dashboard/uploads/";
    $head = $_FILES["head"]["name"];
    $headtype = $_FILES["head"]["type"];
    $headtemp = $_FILES["head"]["tmp_name"];
    move_uploaded_file($headtemp, $path.$head);
    $side_profile = $_FILES["side_profile"]["name"];
    $side_profiletype = $_FILES["side_profile"]["type"];
    $side_profiletemp = $_FILES["side_profile"]["tmp_name"];
    move_uploaded_file($side_profiletemp, $path.$side_profile );
    $full = $_FILES["full"]["name"];
    $fulltype = $_FILES["full"]["type"];
    $fulltemp = $_FILES["full"]["tmp_name"];
    move_uploaded_file($fulltemp, $path.$full);

$htmlbody =  "
        <div style='padding: 40px;'>
    <div style='padding:10px;'>
        <div style='width:100%;text-align:center;padding: 20px 0;'>
            <h2>A User has shown interest to become a model</h2>
        </div>

        <div style='margin:20px auto;font-size:14px;margin-top:40px;'>
        <b>Hello</b> 
            <br/><br/>
        There is a new request submitted by a user. Further details are mentioned below. 
        <h3 style='text-align: center;text-transform: uppercase;font-size: 18px;color: #000;'>Details</h3>
        </div>
    </div>
    <br />

        <div style='margin:20px auto;font-size:14px;margin-top:40px;'>
        <p style='width:20%;float:left'><b>First Name</b></p>
        <p style='width:40%;float:left'>" . $fname . "</p>
        <div style='clear:both;'></div>
        <p style='width:20%;float:left'><b>Surname</b></p>
        <p style='width:40%;float:left'>" . $surname . "</p>
        <div style='clear:both;'></div>
        <p style='width:20%;float:left'><b>Email/b></p>
        <p style='width:40%;float:left'>" . $email . "</p>
        <div style='clear:both;'></div>
        <p style='width:20%;float:left'><b>Date Of Birth</b></p>
        <p style='width:40%;float:left'>" . $date_of_birth . "</p>
        <div style='clear:both;'></div>
        <p style='width:20%;float:left'><b>Height</b></p>
        <p style='width:40%;float:left'>" . $height . "</p>
        <div style='clear:both;'></div>
        <p style='width:20%;float:left'><b>Age</b></p>
        <p style='width:40%;float:left'>" . $age . "</p>
        <div style='clear:both;'></div>
        <p style='width:20%;float:left'><b>Gender</b></p>
        <p style='width:40%;float:left'>" . $gender . "</p>
        <div style='clear:both;'></div>
        <p style='width:20%;float:left'><b>Address</b></p>
        <p style='width:40%;float:left'>" . $address . "</p>
        <div style='clear:both;'></div>
        <p style='width:20%;float:left'><b>Instagram</b></p>
        <p style='width:40%;float:left'>" . $instagram . "</p>
        <div style='clear:both;'></div>
        <p style='width:20%;float:left'><b>Facebook</b></p>
        <p style='width:40%;float:left'>" . $facebook . "</p>
        <div style='clear:both;'></div>

    <br/><br/>
    <p>For further details please login to your account.</p>
    <span style='color:#000;'><b>Thank You</b></span>
</div>
    ";


    $to = "mark.alan112@gmail.com"; //Recipient Email Address

    $subject = "A user had show interest"; //Email Subject

    $headers = "From: name@domain.com\r\nReply-To: name@domain.com";

    $random_hash = md5(date('r', time()));

    $headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";


    $attachment  = chunk_split(base64_encode(file_get_contents($path.$head)));
    $attachment .= chunk_split(base64_encode(file_get_contents($path.$side_profile)));
    $attachment .= chunk_split(base64_encode(file_get_contents($path.$full)));
    //define the body of the message.

    $message = "--PHP-mixed-$random_hash\r\n"."Content-Type: multipart/alternative; boundary=\"PHP-alt-$random_hash\"\r\n\r\n";
    $message .= "--PHP-alt-$random_hash\r\n"."Content-Type: text/plain; charset=\"iso-8859-1\"\r\n"."Content-Transfer-Encoding: 7bit\r\n\r\n";

    //Insert the html message.
    $message .= $htmlbody;
    $message .="\r\n\r\n--PHP-alt-$random_hash--\r\n\r\n";

    //include attachment
    $message .= "--PHP-mixed-$random_hash\r\n"."Content-Type: application/zip; name=\"".$head."\"\r\n"."Content-Transfer-Encoding: base64\r\n"."Content-Disposition: attachment\r\n\r\n";
    $message .= "--PHP-mixed-$random_hash\r\n"."Content-Type: application/zip; name=\"".$side_profile."\"\r\n"."Content-Transfer-Encoding: base64\r\n"."Content-Disposition: attachment\r\n\r\n";
    $message .= "--PHP-mixed-$random_hash\r\n"."Content-Type: application/zip; name=\"".$full."\"\r\n"."Content-Transfer-Encoding: base64\r\n"."Content-Disposition: attachment\r\n\r\n";
    $message .= $attachment;
    $message .= "/r/n--PHP-mixed-$random_hash--";

    //send the email
    $mail = mail( $to, $subject , $message, $headers );

请让我知道我在哪里以及我缺少什么

       <div class="picture_sec">
        <div class="container">
        <div class="lb-put">
            <label>Head Shot</label>
            <input type="file" class="form-control" name="head">
        </div>

        <div class="lb-put">
            <label>Side Profile</label>
            <input type="file" class="form-control" name="side_profile">
        </div>

        <div class="lb-put">
            <label>Full Length</label>
            <input type="file" class="form-control" name="full">
        </div>
        </div>
    </div>  

1 个答案:

答案 0 :(得分:4)

  

“@ Fred-ii-请发表您对php mailer的评论以回答它为我解决了所以我可以接受 - Mark Alan”

根据OP的要求(提供更多信息):

使用PHP的mail()函数,PHPMailer更容易/更好地用于附加文件,并且需要更多语法,这对某些人来说可能会有问题。

它具有现成的语法,可以让您轻松附加文件。

请参阅以下链接,下载并安装。

Swiftmailer也是您可能想要研究的另一个: