문제

다음 $ 헤더는 PHP를 통해 전송됩니다. mail($to,$subject,$content,$header) 명령. 메일이 도착하여 첨부 파일이있는 것으로 보입니다. 그러나 메일 텍스트는 파일과 마찬가지로 비어 있습니다. 나는 이것이 라인 간격과 관련이 있다고 생각하지만 문제를 볼 수 없습니다. 나는 내용물을 (경계 사이)에 넣었다. $contents 그것을 추가하기보다는 $header. 그것은 차이를 만들지 않습니다. 이견있는 사람?

From: dnagirl@someplace.com 
Reply-To: dnagirl@someplace.com 
X-Mailer: PHP 5.3.1
MIME-Version: 1.0
Content-Type: multipart/mixed;
    boundary="7425195ade9d89bc7492cf520bf9f33a"

--7425195ade9d89bc7492cf520bf9f33a
Content-type:text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 7bit

this is a test message.

--7425195ade9d89bc7492cf520bf9f33a
Content-Type: application/pdf; name="test.pdf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="test.pdf"

JVBERi0xLjMKJcfsj6IKNSAwIG9iago8PC9MZW5ndGggNiAwIFIvRmlsdGVyIC9GbGF0ZURlY29k
ZT4+CnN0cmVhbQp4nE2PT0vEMBDFadVdO4p/v8AcUyFjMmma5CqIIF5cctt6WnFBqLD1+4Np1nY3
c3lvfm+GyQ4VaUY11iQ2PTyuHG5/Ibdx9fIvhi3swJMZX24c602PTzENegwUbNAO4xcoCsG5xuWE
.
... the rest of the file
.
MDAwMDA2MDYgMDAwMDAgbiAKMDAwMDAwMDcwNyAwMDAwMCBuIAowMDAwMDAxMDY4IDAwMDAwIG4g
CjAwMDAwMDA2NDcgMDAwMDAgbiAKMDAwMDAwMDY3NyAwMDAwMCBuIAowMDAwMDAxMjg2IDAwMDAw
IG4gCjAwMDAwMDA5MzIgMDAwMDAgbiAKdHJhaWxlcgo8PCAvU2l6ZSAxNCAvUm9vdCAxIDAgUiAv
SW5mbyAyIDAgUgovSUQgWzxEMURDN0E2OUUzN0QzNjI1MDUyMEFFMjU0MTMxNTQwQz48RDFEQzdB
NjlFMzdEMzYyNTA1MjBBRTI1NDEzMTU0MEM+XQo+PgpzdGFydHhyZWYKNDY5MwolJUVPRgo=


--7425195ade9d89bc7492cf520bf9f33a--

$header 라인 브레이크없이 끝납니다

도움이 되었습니까?

해결책

아래 코드를 사용하여 첨부 파일과 HTML 및 문자 메시지 부품이 포함 된 메시지를 보냅니다. 나는 그것을 올바르게하기 위해 오랫동안 싸우는 것을 기억하지만 불행히도 어떤 부분이 내 문제인지 기억하지 못합니다. 어쩌면 그것을 보면 도움이 될 것입니다. 관련이없는 변수를 변경하여 읽기 쉽게 읽을 수 있기를 바랍니다. 이상한 것이 이상하거나 불분명한지 물어보십시오. 설명하려고 노력할 것입니다.

public function sendEmail($htmlString)
{
    $random_hash = md5(date('r', time()));

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

    // text message
    $message .= strip_tags($htmlString) . "\n\n";

    $message .= '--alt-' . $random_hash . "\n";
    $message .= 'Content-Type: text/html; charset="iso-8859-1"' . "\n";
    $message .= 'Content-Transfer-Encoding: 7bit' . "\n\n";

    // html message
    $message .= $htmlString . "\n\n";

    $message .= '--alt-' . $random_hash . '--' . "\n";

    // graph image
    if($this->selectedGraph != 0)
    {
        $graphString = $this->getGraph(); // image attachment
        $graphString = chunk_split(base64_encode($graphString));

        $linkID = 'graph-' . $userInfo['FirmID'] . $random_hash . '-image';

        $message .= '--mixed-' . $random_hash . "\n";
        $message .= 'MIME-Version: 1.0' . "\n";
        $message .= 'Content-Transfer-Encoding: base64' . "\n";
        $message .= 'Content-ID: ' . $linkID . "\n";
        $message .= 'Content-Type: image/gif; name="graph.gif"' . "\n";
        $message .= 'Content-Disposition: attachment' . "\n\n";

        $message .= $graphString;
        $message .= '--mixed-' . $random_hash . '--' . "\n";

    }
    else
    {
        $message .= '--mixed-' . $random_hash . '--' . "\n";
    }


    $headers = 'From: ' . $this->from. "\r\nReply-To: " . $this->replyto;
    $headers .= "\r\nContent-Type: multipart/related; boundary=\"mixed-" . $random_hash . "\"\r\nMIME-Version: 1.0";

    $flags = '-f ' . BOUNCED_EMAIL_ADDRESS;

    return mail($userInfo['Email'], $this->subject, $message, $headers, $flags);

}

다른 팁

이런 일은 마임 메일을 처음부터 구축 할 때 발생합니다. 시원하고 호환 가능한 MIME 메시지를 생성하는 데 사용할 수있는 몇 가지 PHP 모듈이 있습니다. mail_mime 트릭을해야합니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top