簡體   English   中英

郵件功能無法正常工作

[英]mail function not working properly

有人可以幫我解決我的郵件功能問題嗎?

我想在表格和附件中接收文本值。 現在,我收到的是表代碼,而不是代碼輸出和附件。

而且,如果我刪除對附件所做的修改,那么我會得到正確的輸出,但只有文本。

            <?php
            include("config.php");

                 $firstname = $_POST['firstname'];
                 $lastname = $_POST['lastname'];
                 $email = $_POST['email'];
                 $fn1 = $_POST['fn1'];
                 $fn2 = $_POST['fn2'];
                 $fn3 = $_POST['fn3'];
                 $fn4 = $_POST['fn4'];
                 $fn28= $_POST['fn28'];


                $subject = 'test';


                //get file details we need
                $file_tmp_name    = $_FILES['fn28']['tmp_name'];
                $file_name        = $_FILES['fn28']['name'];
                $file_size        = $_FILES['fn28']['size'];
                $file_type        = $_FILES['fn28']['type'];
                $file_error       = $_FILES['fn28']['error'];

                $handle = fopen($file_tmp_name, "r");
                $content = fread($handle, $file_size);
                fclose($handle);
                $encoded_content = chunk_split(base64_encode($content));


                    $boundary = md5("vikas"); 
                    //header
                    $headers = "MIME-Version: 1.0\r\n"; 
                    $headers .= "From:".$email."\r\n"; 
                    $headers .= "Reply-To: ".$email."" . "\r\n";
                    $headers .= "Content-Type: multipart/mixed; boundary = $boundary\r\n\r\n"; 

                    $msg = "
                        <table border='1'>
                        <tbody>
                            <th>
                                <td><h3>Contact Information</h3></td>
                            </th>
                            <tr>
                                <td><b>Borrower's Full Name</b></td>
                                <td><span style='color:#F34536;'> $firstname $lastname </span></td>
                            </tr>
                            <tr>
                                <td><b>Email</b></td>
                                <td><span style='color:#F34536;'> $email</span></td>
                            </tr>
                            <tr>
                                <td><b>Attach Key Documents (optional)</b></td>
                                <td><span style='color:#F34536;'> $fn28</span></td>
                            </tr>
                        </tbody>
                        </table>
                    ";

                    $msg1 = chunk_split(base64_encode($msg));

                    //plain text 
                    $body = "--$boundary\r\n";
                    $body .= "Content-Type: text/plain; charset=ISO-8859-1\r\n";
                    $body .= "Content-Transfer-Encoding: base64\r\n\r\n"; 
                    $body .= $msg1; 

                    //attachment
                    $body .= "--$boundary\r\n";
                    $body .="Content-Type: $file_type; name=\"$file_name\"\r\n";
                    $body .="Content-Disposition: attachment; filename=\"$file_name\"\r\n";
                    $body .="Content-Transfer-Encoding: base64\r\n";
                    $body .="X-Attachment-Id: ".rand(1000,99999)."\r\n\r\n"; 
                    $body .= $encoded_content; 

                    mail($toemail, $subject, $body, $headers)

            ?>

是因為您有這行:

$body .= "Content-Type: text/plain; charset=ISO-8859-1\r\n";

所有代碼均以text-plain發送,將其刪除並將其更改為$header text/html

$header .= 'MIME-Version: 1.0\r\n';
$header .= 'Content-type: text/html; charset=iso-8859-1\r\n';

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM