Wednesday, June 18, 2014

html formatted contact form with attachment link

If you are looking for a contact form which can send html formatted email to the recipient and if you have little bit knowledge about php you can try this html contact form with attachment link. it will send a html formatted  to the recipient.

HTML CODE

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title></title>
<meta name="" content="">
</head>
<body>
<form method="POST" action="attachmail.php" enctype="multipart/form-data">
<table>
<tr>
<td>Nname</td>
<td><input type="text" name="name"/></td>
</tr>
<tr>
<td>Email</td>
<td><input type="text" name="email"/></td>
</tr>
<tr>
<td>Phone</td>
<td><input type="text" name="phone"/></td>
</tr>
<tr>
<td>message</td>
<td><textarea name="comments" id="comments" class="field" tabindex="6"></textarea></td>
</tr>
<tr>
<td>select a file*</td>
<td><input name="file" id="file" type="file" tabindex="7"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" value="submit"/></td>
</tr>
</table>
</form>
</body>

</html>

php attachment.php

<?php
$to = "someone@reciver.com"; //change recivers email address
$from = $_POST['email'];
$subject = "attachment mail"; //change subject
$headers          = 'MIME-Version: 1.0' . "\r\n";
$headers         .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers         .= "From: The Sender $from" . "\r\n";

$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$comments = $_POST['comments'];
$imglink = $_FILES["file"]["name"];

$allowedExts = array("gif", "jpeg", "jpg", "png");
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);

if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/jpg")
|| ($_FILES["file"]["type"] == "image/pjpeg")
|| ($_FILES["file"]["type"] == "image/x-png")
|| ($_FILES["file"]["type"] == "image/png"))
&& ($_FILES["file"]["size"] < 200000000)
&& in_array($extension, $allowedExts)) {
  if ($_FILES["file"]["error"] > 0) {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
  } else {
    echo "Upload: " . $_FILES["file"]["name"] . "<br>";
    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"]);
      echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
      $message = "<html>
<body>
<p><strong>Name:</strong> <br>$name</p>
<p><strong>Phone:</strong> <br>$phone</p>
<p><strong>Email:</strong> <br>$email</p>
<p><strong>Quote Information</strong> <br>$comments</p>
<p><strong>Submitted Files</strong></p>
<hr>
<a href='upload/$imglink'>$imglink</a>
</body>
</html>";
    }
  }
} else {
  echo "Invalid file";
}



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

?>

0 comments:

Post a Comment