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.

Wednesday, November 28, 2012

SCHEDULING AUTOMATIC BACKUP OF DATABASE (MYSQL)

Steps :-
  1. Create a bath file(.bat extension)in notepad.
    • Open notepad and write the queries of MySQL and save it as file-name.bat
    • use Mysqldump statement to create a backup of your database. 
    • (ex. mysqldump database_name -u user -ppassword >backup.sql)
NOTE:If you want the file to be stored with current date, use the below mention code for extracting date particulars {yyyy_mm_dd}

@echo off

    set year=%date:~10,4%
    set mnth=%date:~4,2%
    set day=%date:~7,2%

    set d=%year%_%mnth%_%day%.sql
      mysqldump test -u root -pmysqlpassword >%d%

      2.Schedule task using windows task scheduler   
        • GOTO: Control Panel\System and Security\Administrative Tools
        • select task scheduler and create a new task
        • configure it according to the requirements
        • Under action select "start a new program" and open the batch file created. 

      Monday, September 10, 2012

      URL Rewrite in IIS 7 server



      Following  steps are to be implement:-


      Step 2: Install Module, after complete installation, in IIS the url rewrite module service added automatically.

      Steps 3: Double click on url rewrite module, now click on add rules actions, select user friendly service, click OK.

      Steps 4: New Window appears , now here we write the complete url of application with aspx page name.

      For e.g.: localhost/test/login.aspx

      Check Create corresponding Redirect Rule, Click OK.

      Steps 5: Now run our application  through on IIS server.

      Steps 6: Now our aspx page url looks like as:
                     localhost:8080/test/login

      Thursday, March 1, 2012

      Could not load file or Assembly

      ERROR : Could not load file or assembly "any dll file name" or one of its dependencies.An attempt was made to load a program with an incorrect format.

      SOLUTION:

      ~ Open IIS.
      ~ Right click on 'Application Pool' and select Advance Setting.
      ~ Set "Enable 32-bit Applications" to "True".