How can one effectively search for information about multipart-mails related to PHP?
To effectively search for information about multipart-mails related to PHP, one can start by using specific keywords such as "PHP multipart mail", "PHP email attachments", or "PHP MIME email". Additionally, searching on reputable websites like PHP.net, Stack Overflow, or GitHub can provide valuable insights and code examples on how to work with multipart mails in PHP.
// Example PHP code for sending a multipart mail with attachments
$to = "recipient@example.com";
$subject = "Test Email with Attachment";
$message = "This is a test email with attachment.";
$from = "sender@example.com";
$filename = "example.pdf";
$file = "/path/to/example.pdf";
$content = file_get_contents($file);
$content = chunk_split(base64_encode($content));
$uid = md5(uniqid(time()));
$headers = "From: ".$from."\r\n";
$headers .= "Reply-To: ".$from."\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
$headers .= "This is a multi-part message in MIME format.\r\n";
$headers .= "--".$uid."\r\n";
$headers .= "Content-type:text/plain; charset=iso-8859-1\r\n";
$headers .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$headers .= $message."\r\n\r\n";
$headers .= "--".$uid."\r\n";
$headers .= "Content-Type: application/pdf; name=\"".$filename."\"\r\n";
$headers .= "Content-Transfer-Encoding: base64\r\n";
$headers .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
$headers .= $content."\r\n\r\n";
$headers .= "--".$uid."--";
mail($to, $subject, "", $headers);