How to send doc file to mail in php

To send a DOC file via email in PHP, you can use the mail() function or a PHP email library like PHPMailer. Here's an example using the mail() function:

<?php
// Define the email details
$to = '[email protected]';
$subject = 'Sending a DOC file via email';
$from = '[email protected]';
$doc_file = 'path/to/your/docfile.doc';

// Define the email headers
$headers = 'From: '. $from. "\r\n".
           'Reply-To: '. $from. "\r\n".
           'MIME-Version: 1.0'. "\r\n".
           'Content-Type: application/msword'. "\r\n";

// Define the email body
$body = 'This is the email body';

// Read the DOC file
$doc_file_contents = file_get_contents($doc_file);

// Send the email
mail($to, $subject, $body, $headers, $doc_file_contents);
?>

In this example, we're using the file_get_contents() function to read the contents of the DOC file and then sending it as an attachment using the mail() function.

If you're using PHPMailer, you can use the following code:

<?php
require_once 'PHPMailer/PHPMailer.php';
require_once 'PHPMailer/SMTP.php';

// Create a new PHPMailer instance
$mail = new PHPMailer\PHPMailer\PHPMailer();

// Set the email details
$mail->setFrom('[email protected]');
$mail->addAddress('[email protected]');
$mail->Subject = 'Sending a DOC file via email';

// Read the DOC file
$doc_file_contents = file_get_contents('path/to/your/docfile.doc');

// Add the DOC file as an attachment
$mail->addAttachment($doc_file_contents, 'docfile.doc', 'application/msword');

// Set the email body
$mail->Body = 'This is the email body';

// Send the email
$mail->send();
?>

In this example, we're using the addAttachment() method to add the DOC file as an attachment and then sending the email using the send() method.

Make sure to replace the placeholders (path/to/your/docfile.doc, [email protected], [email protected]) with your actual file path, sender email, and recipient email.