Reputation: 199
hello I am working on html form submission via email. Server side scripting is P H P . my html form is
<form action='sendmail.php' method='post'>
Name:<input type="text" name="name">
File:<input type='file' name='attach'>
<input type="submit">
My php file for sending email is
<?php
$strTo = "[email protected]";
$strHeader .= "From: ".$_POST["name"]."<".$_POST["name"].">";
$strHeader .= "MIME-Version: 1.0\n";
$strHeader .= "MIME-Version: 1.0\n";
$strHeader .= "Content-Type: multipart/mixed; boundary=\"".$strSid."\"\n\n";
$strHeader .= "This is a multi-part message in MIME format.\n";
$strHeader .= "--".$strSid."\n";
$strHeader .= "Content-type: text/html; charset=utf-8\n";
$strHeader .= "Content-Transfer-Encoding: 7bit\n\n";
$strHeader .= $strMessage."\n\n";
if($_FILES["attach"]["name"] != "")
{
$strFilesName = $_FILES["fileAttach"]["name"];
$strContent = chunk_split(base64_encode(file_get_contents($_FILES["fileAttach"]["tmp_name"])));
$strHeader .= "--".$strSid."\n";
$strHeader .= "Content-Type: application/octet-stream; name=\"".$strFilesName."\"\n";
$strHeader .= "Content-Transfer-Encoding: base64\n";
$strHeader .= "Content-Disposition: attachment; filename=\"".$strFilesName."\"\n\n";
$strHeader .= $strContent."\n\n";
}
$flgSend = @mail($strTo,"no-subjet",null,$strHeader);
but its not going in if condition
Upvotes: 0
Views: 538
Reputation: 11112
Try replacing your form with this:
<form action="sendmail.php" method="post" enctype="multipart/form-data">
Name:<input type="text" name="name">
File:<input type="file" name="attach" id="attach">
<input type="submit">
</form>
The enctype attribute in the form is important.
See following link for more details: http://www.w3schools.com/php/php_file_upload.asp
Also ensure all the names in PHP match with HTML, such as the name of file input is attach, so it should be the same in PHP.
if($_FILES["attach"]["name"] != "")
{
$strFilesName = $_FILES["attach"]["name"];
...
}
Upvotes: 7