Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

XML
<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.
Posted
Updated 26-Jul-15 20:29pm
v2

1 solution

I'd guess your problem is with the line
$file_to_attach="/".$uploaddir.$_FILES['file']['name'];
Everywhere else you use $uploaddir as a relative directory (relative to your document root, presumably), but here you are making it an absolute path with the leading / .

Peter
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900