Skip to content

Instantly share code, notes, and snippets.

@aamahi
Last active September 21, 2019 21:21
Show Gist options
  • Save aamahi/a0be5898461d12d20f5d7bcff8248d33 to your computer and use it in GitHub Desktop.
Save aamahi/a0be5898461d12d20f5d7bcff8248d33 to your computer and use it in GitHub Desktop.
PHP - sending e-mail attachments.php
<?php
$to = "yourmail@gmail.com";
$from="mans@example.com";
$subject = "Web Application Develoaper\n";
$mainMessage ="Softwear Engineer\r\n";
$fileName="./mahi.pdf";
$fileNewName ="cv.pdf";
$fileData = file_get_contents($filename);
$boundary = "Hear is Boundary";
$headers = "From :{$from}";
$headers .= "MIME-Version :1.0 \r\n";
$headers .= "Content-type:multipart/mixed; \r\n";
$headers .= "boundary = \"{$boundary}\";\r\n";
$message = "This is Multipart-message\r\n";
$message .= "--{$boundary}\r\n";
$message .= "Content-type:text/plain; charset = UTF-8;\r\n";
$message .= "Content-Transfar-Encodeing : 7bit \r\n";
$message .= $mainMessage."\r\n";
$encodeFileData = chunk_split(base64_encode($fileData));
$message .= "--{$boundary}\r\n";
$message .= "Content-type:aaplication/pdf\r\n";
$message .= "name = {$fileName} \r\n";
$message .= "Content-Transfar-Encodeing :base64 \r\n";
$message .= $encodeFileData ."\r\n";
$message .= "--{$boundary}--\r\n";
$mailsend = mail($to,$subject,$message,$headers);
if(!$mailsend){
die("Sending mail Failed\n");
exit();
}else {
echo "Mail send Sucessfully\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment