简体   繁体   English

PHP 送 email 和 PDF 附件

[英]PHP send email with PDF Attachment

How to get attachment instead of code in body?如何在正文中获取附件而不是代码? I am trying to send email with a PDF file attachment我正在尝试发送带有 PDF 文件附件的 email

$to = "$Email";
$email_subject = "Thank You from Admission Cell";
$email_body = "Dear $Name \n Greeting from ........... \n \n ".
"Thank You & Regards \n Admission Cell\n";
$headers .= "MIME-Version: 1.0\r\n"
  ."Content-Type: multipart/mixed; boundary=\"\"";
$headers = "From: Admission Cell<>\n";
$headers .= "Reply-To:";
$file = file_get_contents("/file_path/public_html/admission.pdf");
$email_body .= chunk_split(base64_encode($file));
mail($to,$email_subject,$email_body,$headers);

I am getting an email with BODY like this我得到一个像这样的 BODY 的 email

Thank You & Regards
Admission Cell
JVBERi0xLjQKJeLjz9MKNjcgMCBvYmoKMjYxMgplbmRvYmoKNjYgMCBvYmoKPDwKL0xlbmd0aCAy
NjEyCi9OIDMKL0FsdGVybmF0ZSAvRGV2aWNlUkdCCi9GaWx0ZXIgL0ZsYXRlRGVjb2RlCj4+CnN0
cmVhbQp4AZ2Wd1RT2RaHz703vdASIiAl9Bp6CSDSO0gVBFGJSYBQAoaEJnZEBUYUESlWZFTAAUeH
ImNFFAuDgmLXCfIQUMbBUURF5d2MawnvrTXz3pr9x1nf2ee319ln733XugBQ/IIEwnRYAYA0oVgU
7uvBXBITy8T3AhgQAQ5YAcDhZmYER/hEAtT8vT2ZmahIxrP27i6AZLvbLL9QJnPW/3+RIjdDJAYA
CkXVNjx+JhflApRTs8UZMv8EyvSVKTKGMTIWoQmirCLjxK9s9qfmK7vJmJcm5KEaWc4ZvDSejLtQ
3pol4aOMBKFcmCXgZ6N8B2W9VEmaAOX3KNPT+JxMADAUmV/M5yahbIkyRRQZ7onyAgAIlMQ5vHIO
i/k5aJ4AeKZn5IoEiUliphHXmGnl6Mhm+vGzU/liMSuUw03hiHhMz/S0DI4wF4Cvb5ZFASVZbZlo
ke2tHO3tWdbmaPm/2d8eflP9Pch6+1XxJuzPnkGMnlnfbOysL70WAPYkWpsds76VVQC0bQZA5eGs
T+8gAPIFALTenPMehmxeksTiDCcLi+zsbHMBn2suK+g3+5+Cb8q/hjn3mcvu+1Y7phc/gSNJFTNl

You can use the PHPMailer script.您可以使用 PHPMailer 脚本。

To use PHPMailer:使用 PHPMailer:

  1. Download the PHPMailer script from here: http://github.com/PHPMailer/PHPMailer从这里下载 PHPMailer 脚本: http://github.com/PHPMailer/PHPMailer
  2. Extract the archive and copy the script's folder to a convenient place in your project.提取存档并将脚本的文件夹复制到项目中方便的位置。
  3. Include the main script file -- require_once('path/to/file/class.phpmailer.php');包含主脚本文件——require_once('path/to/file/class.phpmailer.php');

you can find the example here https://stackoverflow.com/a/12302354/4018585你可以在这里找到示例https://stackoverflow.com/a/12302354/4018585

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM