I want to send an email by clicking on a button or hyperlink with an attachment. The file will find itself in the directory where the page is. I am using this code Send email with attachments in php
It gives an error saying that it does not know function mime_content_type (). I want to use it 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);