无法使用phpmailer发送附件? [英] Unable to send attachment using phpmailer?
本文介绍了无法使用phpmailer发送附件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法通过邮件发送附件只有文字内容成功发送。
这是通过我试图发送邮件。
< form action = email.php 方法 = 发布 enctype = multipart / form-data >
< table id = tab_form >
< tr >
< td width = 50% < span class =code-keyword>>
< 输入 type = text class = popInput name = fname 占位符 = < span class =code-keyword>名字 / >
< / td >
< td width = 50% >
< 输入 ty pe = text class = popInput name = lname 占位符 = 姓氏 / >
< / td >
< / tr >
< tr >
< td width = 50% >
< 输入 type = text class = popInput 名称 = LLno p laceholder = 联系固定电话号码 / >
< / td >
< td width = 50% >
< 输入 type = text < span class =code-attribute> class = popInput name = Mno 占位符 = 联系手机号码 / >
< / td >
< / tr >
< tr >
< td colspan = 2 >
< input type = email class = popInput name = 电子邮件 占位符 = 电子邮件地址 / >
< / td >
< / tr >
< tr >
< td colspan = 2 >
< 输入 类型 = text class = popInput 名称 = position 占位符 < span class =code-keyword> = 位置适用于 / >
< / td >
< / tr >
< tr >
< td colspan = 2 >
< textarea 名称 = 其他 占位符 = < span class =code-keyword>其他评论 > < / textarea >
< / td >
< / tr >
< tr >
< td >
< 输入 type = < span class =code-keyword> file name = file class = popInput / >
< span class =code-keyword>< / td >
< / tr >
< tr >
< td < span class =code-attribute> align = center >
< 输入 type = submit 名称 = 提交 / >
< / td >
< td align = 中心 >
< input type = button value = 重置 / >
< / td >
< / tr > ;
< / table >
< / form >
并且email.php在这里:
<?php
include(class.phpmailer.php);
$ email = new PHPMailer();
$ email-> From = $ _ POST [Email];
$ email-> FromName = $ _ POST [fname]。。$ _ POST [lname];
$ email-> Subject =申请。$ _ POST [position];
$ body = $ _ POST [fname]。。$ _ POST [lname]。\ n;
$ body。= $ _ POST [LLno]。\ n。$ _ POST [Mno]。\ n;
$ body。=其他评论:。$ _ POST [additional];
$ email-> Body = $ body;
$ email-> addAddress('didinesh@xyz.com');
$ uploaddir =uploads /;
$ uploadfile = $ uploaddir.basename($ _ FILES ['file'] ['name']);
echo $ uploadfile;
if(move_uploaded_file($ _ FILES ['file'] ['tmp_name'],$ uploadfile)){
}
else
{
// echofile没上传;
}
$ file_to_attach =/。$ uploaddir。$ _ FILES ['file'] ['name'];
$ file = $ _ FILES ['file'] ['name'];
$ email-> addAttachment($ file_to_attach,$ file);
返回$ email-> send();
?>
< script language =javascript>
alert(电子邮件发送成功);
window.location =index.php;
< / script>
请帮我解决这个问题。
解决方案
email = new PHPMailer();
email-> From =
_POST [Email];
Hi,
I am unable to send attachment with the mail only textual contents are successfully sent.
Here is the form through which I am trying to send mail.
<form action="email.php" method="post" enctype="multipart/form-data">
<table id="tab_form">
<tr>
<td width="50%">
<input type="text" class="popInput" name="fname" placeholder="First Name"/>
</td>
<td width="50%">
<input type="text" class="popInput" name="lname" placeholder="Last Name"/>
</td>
</tr>
<tr>
<td width="50%">
<input type="text" class="popInput" name="LLno" placeholder="Contact Landline Number"/>
</td>
<td width="50%">
<input type="text" class="popInput" name="Mno" placeholder="Contact Mobile Number"/>
</td>
</tr>
<tr>
<td colspan="2">
<input type="email" class="popInput" name="Email" placeholder="Email Address"/>
</td>
</tr>
<tr>
<td colspan="2">
<input type="text" class="popInput" name="position" placeholder="Position Applied for"/>
</td>
</tr>
<tr>
<td colspan="2">
<textarea name="additional" placeholder="Additional Comments"></textarea>
</td>
</tr>
<tr>
<td>
<input type="file" name="file" class="popInput"/>
</td>
</tr>
<tr>
<td align="center">
<input type="submit" name="Submit" />
</td>
<td align="center">
<input type="button" value="Reset" />
</td>
</tr>
</table>
</form>
And the email.php is here:
<?php include("class.phpmailer.php"); $email=new PHPMailer(); $email->From=$_POST["Email"]; $email->FromName=$_POST["fname"]." ".$_POST["lname"]; $email->Subject="Application for ".$_POST["position"]; $body=$_POST["fname"]." ".$_POST["lname"]."\n"; $body.=$_POST["LLno"]."\n".$_POST["Mno"]."\n"; $body.="Additional Comments: ".$_POST["additional"]; $email->Body=$body; $email->addAddress('dinesh@xyz.com'); $uploaddir="uploads/"; $uploadfile=$uploaddir.basename($_FILES['file']['name']); echo $uploadfile; if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)) { } else { //echo "file not uploaded"; } $file_to_attach="/".$uploaddir.$_FILES['file']['name']; $file=$_FILES['file']['name']; $email->addAttachment($file_to_attach,$file); return $email->send(); ?> <script language="javascript"> alert("Email Send Sucessfully"); window.location = "index.php"; </script>
Kindly help me through this problem.
解决方案
email=new PHPMailer();
email->From=
_POST["Email"];
这篇关于无法使用phpmailer发送附件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文