php添加附件,通过PHPMailer添加附件
我有以下
PHPMailer代码.问题是文件成功上传到服务器,但是邮件中没有发送附件.附件代码似乎是我所知的最好的.请检查代码,让我知道我在哪里出错了.
形成
Title * |
Title Mr. Ms. Mrs. |
First Name * |
|
Last Name * |
|
Email Address * |
|
Telephone Number * |
|
Details |
|
Or upload a file (only word, excel or pdf) |
|
send1.php
require('PHPMailer/class.phpmailer.php');
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
//$email_to = "hidden";
//$email_subject = "Request for Portfolio check up from ".$first_name." ".$last_name;
$title = array('Title', 'Mr.', 'Ms.', 'Mrs.');
$selected_key = $_POST['title'];
$selected_val = $title[$_POST['title']];
$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$comments = $_POST['comments']; // required
if(($selected_key==0))
echo "";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message = "";
$email_message .="Title: ".$selected_val."\n";
$email_message .= "First Name: ".clean_string($first_name)."\n";
$email_message .= "Last Name: ".clean_string($last_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "Comments: ".clean_string($comments)."\n";
$allowedExts = array("doc", "docx", "xls", "xlsx", "pdf");
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);
if ((($_FILES["file"]["type"] == "application/pdf")
|| ($_FILES["file"]["type"] == "application/msword")
|| ($_FILES["file"]["type"] == "application/excel")
|| ($_FILES["file"]["type"] == "application/vnd.ms-excel")
|| ($_FILES["file"]["type"] == "application/x-excel")
|| ($_FILES["file"]["type"] == "application/x-msexcel")
|| ($_FILES["file"]["type"] == "application/vnd.openxmlformats-officedocument.wordprocessingml.document")
|| ($_FILES["file"]["type"] == "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"))
&& in_array($extension, $allowedExts))
{
if ($_FILES["file"]["error"] > 0)
{
echo "";
}
else
{
$d='upload/';
$de=$d . basename($_FILES['file']['name']);
move_uploaded_file($_FILES["file"]["tmp_name"], $de);
$fileName = $_FILES['file']['name'];
$filePath = $_FILES['file']['tmp_name'];
//add only if the file is an upload
}
}
else
{
echo "";
}
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
//Create a new PHPMailer instance
$mail = new PHPMailer();
//Tell PHPMailer to use SMTP
$mail->IsSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 0;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = "hidden";
//Set the SMTP port number - likely to be 25, 465 or 587
$mail->Port = 25;
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication
$mail->Username = "hidden";
//Password to use for SMTP authentication
$mail->Password = "hidden";
//Set who the message is to be sent from
$mail->SetFrom($email_from, $first_name.' '.$last_name);
//Set an alternative reply-to address
//$mail->AddReplyTo('replyto@example.com','First Last');
//Set who the message is to be sent to
$mail->AddAddress('hidden', 'hidden');
//Set the subject line
$mail->Subject = 'Request for Profile Check up';
//Read an HTML message body from an external file, convert referenced images to embedded, convert HTML into a basic plain-text alternative body
$mail->MsgHTML($email_message);
//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';
//Attach an image file
//$mail->AddAttachment($file);
$mail->AddAttachment($_FILES['file']['tmp_name'], $_FILES['file']['name']);
//Send the message, check for errors
if(!$mail->Send()) {
echo "";
} else {
echo "";
Header('Location: main.php');
}
}
?>
编辑邮件成功发送所有的细节.只是附件不会发送.
编辑2:解决更改$mail-> MsgHTML到$mail->正文它工作!
php添加附件,通过PHPMailer添加附件相关推荐
- odoo14 ir.attachment附件上传与附件预览功能
一.附件上传 这里收集了三种附件上传方式: 1.odoo自带附件上传 安装odoo自带的附件列出及文档模块 这样在编辑界面就可以看到附件上传按钮了(odoo14自己测试没成功,暂时不知道原因) 2. ...
- pdf批量添加图章_关于添加图章,过来人有哪些实用经验
在日常写作中,一些小伙伴习惯在自己作品上签名,就像是每一个公司都有自己的logo.那么如果想要给自己制作的PDF文件盖章,或是在PDF文件中添加上公司的logo该怎么做呢?尽管PDF文档不如word文 ...
- R语言ggplot2可视化分面图、在分面图中的每个直方图中添加均值文本标签、添加均值红色竖线
R语言ggplot2可视化分面图.在分面图中的每个直方图中添加均值文本标签.添加均值红色竖线 目录
- R语言可视化分面图、假设检验分组t检验、可视化单变量分组分面箱图(faceting bar plot)、添加误差条(error bar)、添加p值、添加抖动数据点(jitter points)
R语言可视化分面图.假设检验分组t检验.可视化单变量分组分面箱图(faceting bar plot).添加误差条(error bar).添加p值.添加抖动数据点(jitter points) 目录
- seaborn使用jointplot函数为散点图添加边缘图、添加回归线、为边缘直方图添加密度曲线、自定义边缘直方图的箱体个数bins(Number of Bins to Marginal Plot )
seaborn使用jointplot函数为散点图添加边缘图.添加回归线.为边缘直方图添加密度曲线.自定义边缘直方图的箱体个数bins(Change Number of Bins to Marginal ...
- seaborn使用jointplot函数为散点图添加边缘图、添加回归线、为边缘直方图添加密度曲线、自定义边缘直方图的色彩(Change Color of Marginal Histogram Plot
seaborn使用jointplot函数为散点图添加边缘图.添加回归线.为边缘直方图添加密度曲线.自定义边缘直方图的色彩(Change Color of Marginal Histogram Plot ...
- R语言使用ggpubr包的ggbarplot函数可视化分组条形图(grouped bar plot)、并添加误差条(error bar、误差条显示平均值+/-sd)、不添加填充色、添加jitter抖动
R语言使用ggpubr包的ggbarplot函数可视化分组条形图(grouped bar plot).并添加误差条(error bar.误差条显示平均值+/-sd).不添加填充色.添加jitter抖动 ...
- seaborn使用jointplot函数为散点图添加边缘图、添加回归线、为边缘直方图添加密度曲线、使用ratio函数突出显示边缘图形(focus on Marginal Plot )
seaborn使用jointplot函数为散点图添加边缘图.添加回归线.为边缘直方图添加密度曲线.使用ratio函数突出显示边缘图形(Make Marginal Plot with focus on ...
- 我的世界java版怎么添加光影,《我的世界》中国版光影添加教程 国服怎么添加光影?...
<我的世界>中国版光影添加教程 国服怎么添加光影? 2017-08-29 15:44:01来源:网易论坛编辑:评论(0) <我的世界>中国版已经开测一段时间了,不少玩家都喜欢在 ...
最新文章
- SIM800C SIM卡唯一标识符ICCID
- 局部图像描述子——SIFT(尺度不变特征变换)
- java 大顶堆_107-大顶堆和小顶堆图解说明
- 国二c语言操作题评分标准,全国计算机二级C语言操作题题库.doc
- POJ1321(DFS)
- ssh-keygen -t rsa执行后提示没有权限
- 基础计算机b卷,计算机应用基础B卷.doc
- android 兼容性定义,谷歌释出 Android 7.0 兼容性定义文件,史上最严
- Spring-data-jpa中用@ColumnTransformer注解加密,中文乱码问题(数据库正常,在java代码和页面中乱码)
- Unable to find vcvarsall.bat
- Latex录入参考文献bib.bib文件
- mysql离散查询_MySQL多表查询与子查询
- 视频太大怎么压缩变小?
- 【影分身之术】制作迷人图片小菜一碟——数学与美的极致结合
- 什么是响应式设计?如何实现?
- influxdb学习记录
- Solidity之事件
- 年味究竟是淡了还是浓了?
- div+css实现水平/垂直/水平垂直居中超详解
- SqlSugar学习总结1(基础操作)
热门文章
- Global Illumination_Horizon-Based Ambient Occlusion(HBAO)
- 图像元素遍历及像素值取反
- 2x3OpenMesh译稿:使用并理解OpenMesh-迭代器与循环器
- 自制炒股盯盘神器——python实现(4)
- TortoiseGit工具使用
- 站长文库:新手站长做优化不能忽略的几点
- QPaintDevice: Cannot destroy paint device that is being painted
- HTML+CSS画圆、半圆、扇形、三角形
- Steam客户端更新:Linux增加2倍缩放模式,支持Windows 10的HiDPI
- flask引用bootstrap4框架