728x15 Ads

bar

php mail explanation with example

php mail attachment example <!-- Metadata generated by http://vancouver-webpages.com/META/mk-metas.html --> -->
php mail attachment WITH A ATTACHMENT IN PHP.

For this u need to install  post card(Local SMTP mail server)

/* form */

<html>
<body>

<form action="romit.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file[]" multiple="multiple" id="file"><br>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html> 


*These 3 line code will remove before uploading server, this is use for only local server  Ends*/

romit.php
 
<?php
ini_set("SMTP","mail.AAAA.com"); //mail.yoursite.com should be your local smtp
ini_set("smtp_port","25"); //25 should be your smtp port
ini_set("sendmail_from","drrfiv.sh7@gmail.com");

?>

<?php

/* code for getting files from form */
if ($_FILES["file"]["error"] > 0)
  {
  echo "Error: " . $_FILES["file"]["error"] . "<br>";
  }
else
  {
 // echo "Upload: " . $_FILES["file"]["name"] . "<br>";
 // echo "Type: " . $_FILES["file"]["type"] . "<br>";
 // echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
 // echo "Stored in: " . $_FILES["file"]["tmp_name"];
 
    $fileName =  $_FILES["file"]["name"] ;
    $fileType = $_FILES["file"]["type"];
    $fileSize = $_FILES["file"]["size"];
    $tmpName = $_FILES["file"]["tmp_name"];
  
    $tmpFilePath = $_FILES['file']['tmp_name'];
    //if (file_exists("upload/" . $_FILES["file"]["name"]))
      //{
      //echo $_FILES["file"]["name"] . " already exists. ";
      //}
    //else
      //{
     // move_uploaded_file($_FILES["file"]["tmp_name"],
     // "upload/" . $_FILES["file"]["name"]);
      move_uploaded_file($tmpFilePath,
      "C:/wamp/www/folder/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "folder/" . $_FILES["file"]["name"];
      //echo "Stored in: " . "upload/" . $_FILES["file"]["tmp_name"];
      //}
  
  }

 
  $subject1 = '! Thanks for your assignment submission';
 /******* ‘Please replace the details with the originals credentials [Replace Form Email address with the senders Email address] *******/
    $from1 = trim('AAAAA@kkk.com') ;
    $to1 = 'hromits@srivastava.com';
    $date1 = date('D, d M Y H:i:s T');
    $text1 = "hello";
    $html1 = "Dear Thanks for submitting the assignment for evaluation.";

 $userfile=$_FILES["file"]["name"] ;
 $uid=md5(uniqid( time()));

    $headers1 = 'MIME-Version: 1.0' . "\r\n";

    $headers1 .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"".$uid."\"\r\n\r\n";

  
  
$attachment = chunk_split(base64_encode(file_get_contents($userfile)));

    $headers1 .= "--" . $uid."\r\n";
    $headers1 .= "Content-Type: text/plain; charset=iso-8859-1\r\n";
    $headers1 .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
    $headers1 .= $html1."\r\n\r\n";
  
    $headers1 .= "--" . $uid."\r\n";
    $headers1 .= "Content-Type:".$fileType."; name=\"".$fileName."\"\r\n";
    $headers1 .= "Content-Transfer-Encoding: base64\r\n";
    $headers1 .= "Content-Disposition: attachment;filename=\"".$fileName."\"\r\n";
    $headers1 .= $attachment."\r\n\r\n";
  
    $headers1 .="From:".$from1;

?>

<?php


//send the email
$mail_sent = @mail( $to1, $html1, "", $headers1 );
//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed"
echo $mail_sent ? "Mail sent" : "Mail failed";

?>

 
if this helps u leave a comment...

0 comments:

Post a Comment

Copyright © eAZy EnginEEriNG