Link to home
Start Free TrialLog in
Avatar of Jeffreym17
Jeffreym17

asked on

Modifications in Open Source Codings

I want to add "Attach a File" field to attach any document in the below php script.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Tele Staff CRM</title>
</head>
<body>
<form action="<? echo $_POST['../itell/self']; ?>" method="post">
   <strong>Company Profile: <br />
   <br />
   TME Name:</strong><br />
<input name="name" type="text"><br />
<strong>Client's Name:</strong><br />
<input name="clientname" type="text"><br />
<strong>Client's Email Address:</strong><br />
<input name="email" type="text"><br />
<strong>Client's Mobile Number:</strong><br />
<input name="mobile" type="text"><br />
<strong>Client's Web Site Address:</strong><br />
<input name="website" type="text"><br />
<input name="Send" type="submit" value="Send">
<input type="reset" />
</form>
<?
 
if (@$_POST['Send']=="Send")
{
$name=$_POST['name'];
$clientname=$_POST['clientname'];
$email=$_POST['email'];
$mobile=$_POST['mobile'];
$website=$_POST['website'];
$subject = $name. " sends 20% Discounted OFFER from J Morgan.";
//This is the body section of the email and can be substituted for your message
$message= " Dear " .$clientname. ", \n\nAs per your telephonic conversation with our Tele-Marketing Executive " .$name. " please find below our company details.\n\nOur Company Website is http://www.jmorganinfo.com here you can go through our company profile.\n\n As a global leader in web hosting services J Morgan Technologie Pvt. Ltd. has come up with this unique offer especially for you. With this OFFER you SAVE EVERY YEAR 20% on your present web hosting charges. Besides you will get more features than your present web hosting plan.\n\nYou simply need to reply this email with your latest web hosting bill and within 48 hours you will receive a call from us helping you get your web hosting account set up with the discounted offer.\n\nWe believe in eating our competition, do you too? We are sure you do. So why wait, attach your latest web hosting bill and reply this email right now.\n\nFull Refund 30 Days Money Back Guarantee on Web Hosting.\n\nRegards,\nJ Morgan Technologies Pvt. Ltd.\nSuite 12, First Floor,\nNagree Building, Station Road,\nSantacruz West, Mumbai 400 054\nTele.: +91 22 3213 6720 / 3218 8414 / 3219 9162\nFax: +91 22 6725 3883\nwww.jmorganinfo.com\nwww.hostbaap.com\nwww.websitedesignerseo.com \n\n\nNote: This message was not sent unsolicited.  It was sent through a form located at http://www.jmorganinfo.com If you believe this message was received on error, please disregard it.\n\n\nThe information you have shared with us: ".$mobile." and ".$website."\n\n\n". 
$headers = 'From: hosting@hostbaap.com' . "\r\n" . 'Cc: hosting@hostbaap.com' . "\r\n".'Reply-To: hosting@hostbaap.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion();
mail($email, $subject, $message, $headers); 
echo "You`ve sent information to: $email  Thank you";
}
?>
<br />
<br />
<br />
</body>
 
</html>

Open in new window

Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

You need to upload the file to the server, and then attach it to the email.  Here is my standard file-upload script that you can adapt to your forms above.  I don't have a good "attach file" example for email, but you can split the points with someone who does...

;-)

best regards, ~Ray
<?php // RAY_upload_example.php
 
// ESTABLISH THE NAME OF THE 'uploads' DIRECTORY
$uploads = 'uploads';
 
// ESTABLISH THE BIGGEST FILE SIZE WE CAN ACCEPT
$max_file_size = '8192000';  // EIGHT MEGABYTE LIMIT ON UPLOADS
 
// ESTABLISH THE KINDS OF FILE EXTENSIONS WE CAN ACCEPT
$file_exts = array('jpg', 'gif', 'png', 'txt');
 
// THIS IS A LIST OF THE POSSIBLE ERRORS THAT CAN BE REPORTED in $_FILES[]["error"]
$errors	= array(
	0=>"Success!",
	1=>"The uploaded file exceeds the upload_max_filesize directive in php.ini",
	2=>"The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form",
	3=>"The uploaded file was only partially uploaded",
	4=>"No file was uploaded",
	6=>"Missing a temporary folder",
	7=>"Cannot write file to disk"
);
 
// IF THERE IS NOTHING USEFUL IN $_POST, PUT UP THE FORM FOR INPUT
if ( (empty($_POST['p'])) && (empty($_POST['MAX_FILE_SIZE'])) )
{
	?>
	<h2>Upload a file</h2>
 
	<!-- ENCTYPE -->
	<form name="UploadForm" enctype="multipart/form-data" action="<?=$_SERVER["REQUEST_URI"]?>" method="POST">
	<input type="hidden" name="p" value="1" />
	<!-- MAX_FILE_SIZE must precede the file input field -->
	<input type="hidden" name="MAX_FILE_SIZE" value="<?=$max_file_size?>" />
	<!-- INPUT NAME= IN TYPE=FILE DETERMINES THE NAME FOR ACTION SCRIPT TO USE IN $_FILES ARRAY -->
	<p>
	Find the file you want to upload and click the "Upload" button below.
	</p>
 
	<input name="userfile" type="file" size="80" />
	<br/>Check this box <input autocomplete="off" type="checkbox" name="overwrite" /> to <b>overwrite</b> an existing file.
	<input type="submit" name="_submit" value="Upload" />
	</form>
	<?php
	die();
}
else // WE HAVE GOT SOMETHING IN $_POST
{
 
// THERE IS POST DATA - PROCESS IT
	echo "<h2>Results: File Upload</h2>\n";
	echo "<p>\n";
 
// SYNTHESIZE THE NEW FILE NAME
	$f_type	= trim(strtolower(end    (explode( '.', basename($_FILES['userfile']['name'] )))));
	$f_name	= trim(strtolower(current(explode( '.', basename($_FILES['userfile']['name'] )))));
	$my_new_file	= getcwd() . '/' . $uploads . '/' . $f_name .'.'. $f_type;
	$my_file	= $uploads . '/' . $f_name .'.'. $f_type;
 
// TEST FOR ALLOWABLE EXTENSIONS
	if (!in_array($f_type, $file_exts)) die("Sorry, $f_type files not allowed");
 
// IF THERE ARE ERRORS
	$error_code	= $_FILES["userfile"]["error"];
	if ($error_code != 0)
	{
		$error_message = $errors[$error_code];
		echo "<p class=\"required\">Upload Error Code: $error_code: $error_message</p>\n";
		die('Sorry');
	}
 
// MOVE THE FILE INTO THE DIRECTORY
	$overwrite	= $_POST['overwrite'];
	$file_size	= number_format($_FILES["userfile"]["size"]);
 
// IF THE FILE IS NEW
	if (!file_exists($my_new_file))
	{
		if (move_uploaded_file($_FILES['userfile']['tmp_name'], $my_new_file))
		{
			$upload_success = 1;
		}
		else
		{
			$upload_success = -1;
		}
 
// IF THE FILE ALREADY EXISTS
	}
	else
	{
		echo "<b><i>$my_file</i></b> already exists.\n";
 
// SHOULD WE OVERWRITE THE FILE? IF NOT
		if (empty($overwrite))
		{
			$upload_success = 0;
 
// IF WE SHOULD OVERWRITE THE FILE, TRY TO MAKE A BACKUP
		}
		else
		{
			$now	= date('Y-m-d');
			$my_bak = $my_new_file . '.' . $now . '.bak';
			if (!copy($my_new_file, $my_bak))
			{
				echo "<b>Attempted Backup Failed!</b>\n";
			}
			if (move_uploaded_file($_FILES['userfile']['tmp_name'], $my_new_file))
			{
				$upload_success = 2;
			}
			else
			{
				$upload_success = -1;
			}
		}
	}
 
// REPORT OUR SUCCESS OR FAILURE
	if ($upload_success == 2) { echo "It has been overwritten.\n"; }
	if ($upload_success == 1) { echo "<b><i>$my_file</i></b> has been saved.\n"; }
	if ($upload_success == 0) { echo "<b>It was NOT overwritten.</b>\n"; }
 
	if ($upload_success > 0)
	{
		echo "$file_size bytes uploaded.\n";
		chmod ($my_new_file, 0755);
	}
 
	echo "</p>\n";
	echo "<p><a href=\"$my_file\">See the file</a></p>\n";
	die('Done');
}
?>

Open in new window

Avatar of Jeffreym17
Jeffreym17

ASKER

But how to add it in the above my given script.
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial