Wednesday, May 22, 2013

How to Import Data in MySql from MS SQL SERVER


I have a very good and Easy Steps for import Data in MySql from MS SQL Server.

1.) First of All You have to open Visual Studio 2010.

2.) Go to Server Explorer.

3.) Add a New Connection of MySql.

4.) Add Database which you want to import Data From SQL Server Db.

5.) Add another Connection of MS SQL Server.

6.) Add Database which you want to Export Data for MySql.

7.) Now you have Opened both Databases in Server Explorer of Visual Studio 2010.

8.) Now Right Click on Table (which you want to copy data to MySql) and click on SHOW TABLE DATA.

9.) Now Select All data from your table and Copy that records.

10.) Now Open MySql Database and open same Table (which you want to paste data into) from MySql and Paste all Data you copied from MS SQL SERVER.

Tuesday, May 21, 2013

Send mail with multiple attachments in php

Following these two steps to send multiple attachments in mail.

Step 1: 

<html>  
<head>  
<title>How to send mail in PHP with multiple attachments</title>  
</head>  
<body>    
<form name="sendmail" action="sendmail.php" method="post" enctype="multipart/form-data">  
    <label>E-mail ID:</label>  
    <input name="email" type="text" /><br />  
  
    <label>Subject:</label>  
    <input name="subject" type="text" /><br />  
  
    <label>Body:</label><br />  
    <textarea name="body" rows="4"></textarea><br />  
  
    <label>Attachments:</label><br />  
    <input name="file1" type="file" /><br />  
    <input name="file2" type="file" /><br />  
    <input name="file3" type="file" /><br />  
  
    <input name="submit" type="submit" value="Send Mail" />  
</form>    
</body>  
</html> 

Step 2:  (sendmail.php)

<?php  
$from = "YOUR FROM EMAIL";  
$to = $_POST['email'];  
$subject =$_POST['subject'];  
$message = $_POST['body'];  
  
// Temporary paths of selected files  
$file1 = $_FILES['file1']['tmp_name'];  
$file2 = $_FILES['file2']['tmp_name'];  
$file3 = $_FILES['file3']['tmp_name'];  
  
// File names of selected files  
$filename1 = $_FILES['file1']['name'];  
$filename2 = $_FILES['file2']['name'];  
$filename3 = $_FILES['file3']['name'];  
  
// array of filenames to be as attachments  
$files = array($file1, $file2, $file3);  
$filenames = array($filename1, $filename2, $filename3);  
  
// include the from email in the headers  
$headers = "From: $from";  
  
// boundary  
$time = md5(time());  
$boundary = "==Multipart_Boundary_x{$time}x";  
  
// headers used for send attachment with email  
$headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$boundary}\"";  
  
// multipart boundary  
$message = "--{$boundary}\n" . "Content-Type: text/html; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n";  
$message .= "--{$boundary}\n";  
  
// attach the attachments to the message  
for($x = 0; $x < count($files); $x++) {  
    $file = fopen($files[$x],"r");  
    $content = fread($file,filesize($files[$x]));  
    fclose($file);  
    $content = chunk_split(base64_encode($content));  
    $message .= "Content-Type: {\"application/octet-stream\"};\n" . " name=\"$files[$x]\"\n" . "Content-Disposition: attachment;\n" . " filename=\"$filenames[$x]\"\n" . "Content-Transfer-Encoding: base64\n\n" . $content . "\n\n";  
    $message .= "--{$boundary}\n";  
}  
  
// sending mail  
$sendmail = mail($to, $subject, $message, $headers);  
  
// verify if mail is sent or not  
if ($sendmail) {  
    echo "Mail Sent successfully!";  
} else {  
    echo "Error occurred!!!";  
}  
?> 

Now you learn how to send multiple attachment send in mail using php in simply two steps. special thanks to codegambler.com . Cheers!!!!!