Thursday, June 20, 2013

Send Email With File Attachment In PHP


<?php

$message="<table width='100%' border='0' cellspacing='0' cellpadding='0'>
  <tr>
    <td width='15%' align='left' valign='top'>&nbsp;</td>
    <td width='85%' align='left' valign='top'>&nbsp;</td>
  </tr>
  <tr>
    <td align='left' valign='top'>First Name</td>
    <td align='left' valign='top'><label>" . $_POST['name'] . "</label></td>
  </tr>
  <tr>
    <td align='left' valign='top'>&nbsp;</td>
    <td align='left' valign='top'>&nbsp;</td>
  </tr>
  <tr>
    <td align='left' valign='top'>Last name</td>
    <td align='left' valign='top'><label>".$_POST['last_name']."</label></td>
  </tr>
  <tr>
    <td align='left' valign='top'>&nbsp;</td>
    <td align='left' valign='top'>&nbsp;</td>
  </tr>
  <tr>
    <td align='left' valign='top'>Contact no.</td>
    <td align='left' valign='top'><label>
      ".$_POST['mobile_no']."</label></td>
  </tr>
  <tr>
    <td align='left' valign='top'>&nbsp;</td>
    <td align='left' valign='top'>&nbsp;</td>
  </tr>
  <tr>
    <td align='left' valign='top'> Email</td>
    <td align='left' valign='top'><label>
      ".$_POST['clientEmail']."</label></td>
  </tr>
  <tr>
    <td align='left' valign='top'>&nbsp;</td>
    <td align='left' valign='top'>&nbsp;</td>
  </tr>
  <tr>
    <td align='left' valign='top'>I wish to:</td>
    <td align='left' valign='top'><label>
      ".$_POST['branch']."
    </label></td>
  </tr>
  <tr>
    <td align='left' valign='top'>&nbsp;</td>
    <td align='left' valign='top'>&nbsp;</td>
  </tr>
  <tr>
    <td align='left' valign='top'>&nbsp;</td>
    <td align='left' valign='top'>&nbsp;</td>
  </tr>
  <tr>
    <td align='left' valign='top'>Comments:</td>
    <td align='left' valign='top'><label>
      ".$_POST['comment']."
    </label></td>
  </tr>
  <tr>
    <td align='left' valign='top'>&nbsp;</td>
    <td align='left' valign='top'>&nbsp;</td>
  </tr>

  <tr>
    <td align='left' valign='top'>&nbsp;</td>
    <td align='left' valign='top'>&nbsp;</td>
  </tr>
</table>";

$file_path = $_FILES['attachment']['name']; // server path where file is placed
$file_path_type = $_FILES['attachment']['type']; // File Type
$file_path_name = $_FILES['attachment']['name'];// this file name will be used at reciever end
$url =$_SERVER['HTTP_REFERER'];

 $moved = move_uploaded_file($_FILES["attachment"]["tmp_name"], $_SERVER['DOCUMENT_ROOT']."/".$_FILES["attachment"]["name"]);
 if($moved)
 {
     echo $_SERVER['DOCUMENT_ROOT'].$_FILES["attachment"]["name"];
     echo $_FILES["attachment"]["size"];
     echo "file uploaded";
     }
     else
     {
          echo "file not uploaded";
         }

$from =$clientEmail; // E-mail address of sender
$to = "kamesh.pandey@acetechindia.com"; // E-mail address of reciever
$subject = "Enquiry From wizardzwindow.com"; // Subject of email
$message .= " Thanks";

$headers = "From: ".$_POST['clientEmail'];

$file = fopen($file_path,'rb');
$data = fread($file,filesize($file_path));
fclose($file);

$rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$rand}x";

$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";

$message .= "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type:text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message .= "\n\n";

$data = chunk_split(base64_encode($data));

$message .= "--{$mime_boundary}\n" .
"Content-Type: {$file_path_type};\n" .
" name=\"{$file_path}\"\n" .
"Content-Disposition: attachment;\n" .
" filename=\"{$file_path}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data .= "\n\n" .
"--{$mime_boundary}--\n"; 

if(@mail($to, $subject, $message, $headers)) {
header("Location: $url");

} else {
echo 'Failed';
}
?>

Thursday, February 21, 2013

How to add assembly/dll file in gac(Global assembly cache) on run time


Step 1
first of all make a dll file and give a strong name and write following code in assemblyInfo.cs

for giving strong name right click on project name in visual studio and go to property and now go in signing tab and choose snk name and write following code in "assemblyInfo.cs"
then press ctrl+s for save
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile(@"E:\ktp\ktp\ktp1.snk")]//path for strong name
[assembly: AssemblyKeyName("")]

 now rebulid application again

Step 2
now go to your new project and make a set up now right click on set up and go to view now further go to file system now right click on file system on target machine and add a global assembly cache folder
and now right click on global assembly cache folder and add assembly or dll that we want to add gac


Step3
now rebulid the set up and install set up that dll automatically added in "C:\Windows\Microsoft.NET\assembly\GAC_MSIL\ktp(dll name) location.and we use that dll


By: Dalip Kumar

Wednesday, February 6, 2013

Resetting lost/ forgotten MySQL root password

Steps:
1. Stop the MySQL server process by going in "Services" .
2. Now open notepad & write the following
USE mysql;
UPDATE user SET password=PASSWORD('New password')    WHERE user='root';
FLUSH PRIVILEGES;
In place of 'new password' you can enter enter your new desired password.
3. Now save this notepad file by name of "mysql init.txt" and place it on desktop. 
4. Now open DOS window & enter the path where MySQL is installed ( which is C:/\Program Files by default)
5. Open dir file in  'C:\ Program Files\MySQL\MySQL Server 5.5\bin' and check wether 'my.ini' file is present there.
6. After this come out of bin folder & write the following command
bin\mysqld.exe --defaults-file="my.ini" --init-file="C:\\Users\Administrator\Desktop\mysql init.txt" --console
After this some messages are shown.
7. Now go to 'Services' and start the MySQL server.


8. After this you can work in MySQL by entering new password.   


Friday, January 4, 2013

Troubleshooting responsive website

Question:- When we use data-list of asp.net, it gives trouble while working on responsive website?
Answer:- On using Asp.net Data-list it by-default creates "RepeatLayout=Table". Just change it to "RepeatLayout=Flow" and then it will work perfectly.