Send Email With Attachment(Mail Function)-Full Detail In Hindi

Hello friends kese ho aap sab ajj me apko ek send email with attachment  script ke bare me btane wala hu aap iska use karke apne website me ye function dal sakte ho.

Advantages of send mail with attachment-
Iska use karke koi b visitor apne kisi friend ko email bhej sakta hai wo be attachment ke sath
Is script ka use karke app niche di gye types ki files easily send kar sakte ho.
“pdf", "docx", "doc", "gif", "txt", "jpg", "png", " jpeg
App agar koi or formate ki file send karna chahte ho to aap easily use kar sakte ho

1-sbse pehle aap index.php file bnaiye,is index file me apki html ki coding ayegi
Index.php file ko aap niche diye gye link se download kar sakte ho easily

<!doctype html>
        <link href="style.css" rel="stylesheet" type="text/css"/>
<title>Gajabwap Web In Hindi </title>
       <form method="post" action="mail.php" enctype="multipart/form-data" class="attachment-form">
           <h1>Welcome Our Free Email Send Tool</h1>
            <tr><td><h1>Enter your email</h1><input type="email" name="email"/></td></tr><br>


          <center> <tr><td><h1>Enter your Message </h1><textarea name="msg" ></textarea></td></tr></center><br>
           <center> <tr>
<td><input type="file" name="attach"/><tr></td><br>
          <center>  <tr><td><input type="submit" value="Send"/></td></tr></center>


2-ab apko mail.php file bnani hai yanha apki php coding ayegi
Mail.php file download karne ke liye niche diye gye link par click kare


Php Mail Function



ini_set('display_errors', 1);

 if (isset($_FILES) && (bool) $_FILES) {

     $allowedExtensions = array("pdf", "docx", "doc", "gif", "txt", "jpg", "png", " jpeg ");

// Yanha app apni marji se or be formate dal sakte ho

    $files = array();

    foreach ($_FILES as $name => $file) {

        $file_name = $file['name'];

        $temp_name = $file['tmp_name'];

        $file_type = $file['type'];

        $path_parts = pathinfo($file_name);

        $ext = $path_parts['extension'];

        if (!in_array($ext, $allowedExtensions)) {

            die("File $file_name has the extensions $ext is not allowed");


        array_push($files, $file);


      $to = $_POST['email'];

    $from ="";

     $subject = "your subject here";

      $message = $_POST['msg'];

    $headers = "From: $from";

      $semi_rand = md5(time());

    $mime_boundary = "==Multipart_Boundary_x{$semi_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/plain; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n";

    $message .= "--{$mime_boundary}\n";

      for ($x = 0; $x < count($files); $x++) {

        $file = fopen($files[$x]['tmp_name'], "rb");

        $data = fread($file, filesize($files[$x]['tmp_name']));


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

        $name = $files[$x]['name'];

        $message .= "Content-Type: {\"application/octet-stream\"};\n" . " name=\"$name\"\n" .

                "Content-Disposition: attachment;\n" . " filename=\"$name\"\n" .

                "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";

        $message .= "--{$mime_boundary}\n";


 $ok = mail($to,$subject, $message, $headers);

    if ($ok) {

        echo "

mail sent to $to!


    } else {

        echo "mail sending failed!






                           For Demo Purpose Visit

Ab aap easily is script ko run karwa sakte ho apne website  se. 
Note –is script se mail aap  sirf server se he send kar sakte ho to plz is script ka server par run karo
Me ummid karta hu ki apko ye script achi lgi hogi agar apko script run karwane me oi be problem a rhe hai to aap mujse comment me swal puch sakte hai me apki puri help karunga
                                thank you

Next Post »


Click here for comments
Sultan Singh
14 March 2018 at 04:59 ×

very nice post about send email with attachment full details

sam thakur
14 March 2018 at 07:06 ×

nice post bro apne bhut he achi trah se explain kiya hai send mail with attchment ko nice post hai i like itt

Thanks for your comment