2
I want to send an email by clicking on a link or hyperlink with an attachment. The file will find itself in the directory where the page is. I’m using this code Email with attachments in php
Gives an error saying you don’t know Function mime_content_type(). I want to use without forms.
$boundary = "XYZ-".md5(date("dmYis"))."-ZYX";
$path = '/teste.txt';
$fileType = mime_content_type( $path );
$fileName = basename( $path );
// Pegando o conteúdo do arquivo
$fp = fopen( $path, "rb" ); // abre o arquivo enviado
$anexo = fread( $fp, filesize( $path ) ); // calcula o tamanho
$anexo = chunk_split(base64_encode( $anexo )); // codifica o anexo em base 64
fclose( $fp ); // fecha o arquivo
// cabeçalho do email
$headers = "MIME-Version: 1.0" . PHP_EOL;
$headers .= "Content-Type: multipart/mixed; ";
$headers .= "boundary=" . $boundary . PHP_EOL;
$headers .= "$boundary" . PHP_EOL;
$mensagem .= "Content-Type: ". $fileType ."; name=\"". $fileName . "\"" . PHP_EOL;
$mensagem .= "Content-Transfer-Encoding: base64" . PHP_EOL;
$mensagem .= "Content-Disposition: attachment; filename=\"". $fileName . "\"" . PHP_EOL;
$mensagem .= "$anexo" . PHP_EOL;
$mensagem .= "--$boundary" . PHP_EOL;
$para="[email protected]";
$assunto="teste";
mail($para, $assunto, $mensagem, $headers);
The function equivalent to mime_content_type() is feint
– rray
Gives the same error. I just want the attachment to be attached, type <a href=mailto:[email protected]>email</a> where the mail software opens.
– akm
You want the attachment to turn the body of the email with html formatting?
– rray
No, that appears attached for later the user to insert the subject and the message in the mail software.
– akm