Auto php posta dosya eklemek

2 Cevap php

Ben php postayla bir pdf dosya göndermek isteyen duyuyorum. Ben dosya adını ve konumunu (cup-pdf basılmış bir fatura) bilmek ve benim web sitesinde bir düğmeye tıkladığınızda php otomatik olarak bu gönderilen istiyoruz. Bu nasıl yapılabilir? Teşekkürler

2 Cevap

You should use one of the classes built for that, for example PEAR Mail. For a bit more explanation, assuming we use just a plain text UTF8 content with the PDF file.

  • uniqboundary benzersiz bir dize çeşit ile değiştirmeniz gerekir
  • $fileType dosyanızın MIME türü

İşte kod:

$headers = 'MIME-Version: 1.0'."\r\n"
    .'Content-Type: multipart/related; boundary="--uniqboundary"'."\r\n";

$body = '--uniqboundary."\r\n".
    .'Content-Type: text/plain; charset=utf-8'."\r\n"
    .'Content-Transfer-Encoding: 8bit'."\r\n\r\n"
    .$text
    .'--uniqboundary'."\r\n"
    .'Content-Type: '.$fileType.'; name="'.basename($filename).'"'."\r\n"
    .'Content-Transfer-Encoding: base64'."\r\n"
    .'Content-Disposition: attachment; filename="'.basename($filename).'"'."\r\n\r\n";

$lineSize = filesize($filename) + 1;
$f = fopen($filename, 'r');
$chunks[] = chunk_split(base64_encode(fread($f, $lineSize)));
fclose($f);

$body .= implode("\r\n", $chunks)
    .'--uniqboundary--'."\r\n";

mail($to, $subject, $body, $headers);

Bu çalışması gerekir.

phpmailer bunun için iyi bir seçenek olduğunu, ancak bunu yapmak için bir SMTP hesabı gereklidir