10/10/2018, 10:34
Send file trong email.
Chào các Bro,
Mình đang có 1 project viết 1 module trong send + nhận files trong email của PHP. mình tạo database cho nó mà chưa biết kết nối + phương hướng như thế nào các bro cho mình ý kiên hoặc bro nào có code demo share cho mình với nhé. Cám ơn các bro nhiều.
p/s: http://www.mediafire.com/?fweeyzylvn3 đây là project của mình mình post lên cho các bro tham khao. tài liệu viết bằng tiếng anh mong các bro thông cảm cho mình.
Mình đang có 1 project viết 1 module trong send + nhận files trong email của PHP. mình tạo database cho nó mà chưa biết kết nối + phương hướng như thế nào các bro cho mình ý kiên hoặc bro nào có code demo share cho mình với nhé. Cám ơn các bro nhiều.
p/s: http://www.mediafire.com/?fweeyzylvn3 đây là project của mình mình post lên cho các bro tham khao. tài liệu viết bằng tiếng anh mong các bro thông cảm cho mình.
Bài liên quan
Index.html
-------------------------------------------------
<html>
<head>
<title></title>
</head>
<body marginwidth=4 marginheight=4 topmargin=4 leftmargin=4 bgcolor=white vlink="#0000ff" link="#0000ff">
<form name="Attachments" method=POST action="sendmail.php" enctype="multipart/form-data">
<input type=hidden name=box value="">
<tr>
<td nowrap width="1%"> <b>File:</b></td>
<td colspan=2>
<input type=file name=source_file size=20> <br>
</td>
</tr>
<input type=submit name=btnSubmit value=Next>>> size=20 style="border: 1px solid #0000FF">
</form>
</body>
</html>
-------------------------------------------------
Sendmail.php
-------------------------------------------------
<?php
$ftp_server='www.yourname.com';//serverip
$conn_id = ftp_connect($ftp_server);
// login with username and password
$user="username";
$passwd="******";
$login_result = ftp_login($conn_id, $user, $passwd);
// check connection
if ((!$conn_id) || (!$login_result)) {
echo "FTP connection has failed!";
echo "Attempted to connect to $ftp_server for user $ftp_user_name";
die;
} else {
echo "<br>Connected to $ftp_server, for user $user<br>";
}
//directorylike /www.yourname.com/upload/upload
ftp_chdir($conn_id, "public_html/upload/upload/");
//here we create the unique name for the uploaded file so that it wont overwrite an existing file
$uniqueID = uniqid("");
$destination_file= $uniqueID.".doc";
echo ("<br>");
print $destination_file;
echo ("<br>");
// upload the file
$upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY);
// check upload status
if (!$upload) {
echo "FTP upload has failed!";
} else {
echo "Uploaded $source_file to $ftp_server as $destination_file";
}
// close the FTP stream
ftp_close($conn_id);
?>
<html>
<head>
<title></title>
</head>
<Body>
<form name="form1" method="post" action="mail.php">
<p>
<input name="id" type="text" id="id" value="<?php echo $destination_file; ?>">
</p>
<table width="75%" border="1">
<tr>
<td><div align="right">Name:</div></td>
<td><input name="nume" type="text" id="nume"></td>
</tr>
<tr>
<td><div align="right">Surnume:</div></td>
<td><input name="prenume" type="text" id="prenume"></td>
</tr>
<tr>
<td><div align="right">E- mail: </div></td>
<td><input name="email" type="text" id="email"></td>
</tr>
<tr>
<td><div align="right">Aplication for : </div></td>
<td><input name="post" type="text" id="post"></td>
</tr>
</table>
<p>
<input type="submit" name="Submit" value="Next >>>">
</p>
</form>
</Body>
</html>
-------------------------------------------------
Mail.php
-------------------------------------------------
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<style type="text/css">
<!--
.style17 { font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
}
-->
</style>
</head>
<body>
<p>
</p>
<?php
//to be successfull in useing this code you need to create a directory called upload
//on you ftp create a directory upload in wich copy the content of the zip file
//$filleant takes the value of the picture that was jut uploaded with the unique name to the ftp in the www.yourname.com/upload/upload
$fileatt = "upload/".$_POST['id']; // Path to the file
$fileatt_type = "application/octet-stream"; // File Type
//here i made the file that will be sent as attachment to have the name "CV_name_surname.doc" you can make it what format you like,
//i needed the doc format... and i'll modify this code to accept just doc file later...i'm really tired right now
$fileatt_name = "CV_".$_POST['nume']."_".$_POST['prenume'].".doc"; // Filename that will be used for the file as the attachment
//$email_from is the variable that gets the value, of the From: field that will appear in your received mail
$email_from = $_POST['nume']." ".$_POST['prenume']; // Who the email is from
//Here you define the subject of you message
$email_subject = "CV."; // The Subject of the email
//here you define the body of the message, the message itself
//you can modify the "post" textfield in sendmail.php to a textarea....
$email_message = $_POST['post']; // Message that the email has in it
//here you enter the e-mail address to wich you want the message to be sent
$email_to = "yourname@anywhere.com"; // Who the email is too
//adds the e-mail address of the sender
$headers = "From: ".$_POST['email'];
$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}\"";
$email_message .= "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type:text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$email_message . "\n\n";
/********************************************** First File ********************************************/
//$filleant takes the value of the picture that was jut uploaded with the unique name to the ftp in the www.yourname.com/upload/upload
$fileatt = "upload/".$_POST['id']; // Path to the file
$fileatt_type = "application/octet-stream"; // File Type
//here i made the file that will be sent as attachment to have the name "CV_name_surname.doc" you can make it what format you like,
//i needed the doc format... and i'll modify this code to accept just doc file later...i'm really tired right now
$fileatt_name = "CV".$_POST['nume']."_".$_POST['prenume'].".doc"; // Filename that will be used for the file as the attachment
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
$data = chunk_split(base64_encode($data));
$email_message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
//"Content-Disposition: attachment;\n" .
//" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}\n";
unset($data);
unset($file);
unset($fileatt);
unset($fileatt_type);
unset($fileatt_name);
/********************************************** End of File Config ********************************************/
// To add more files just copy the file section again, but make sure they are all one after the other! If they are not it will not work!
$ok = @mail($email_to, $email_subject, $email_message, $headers);
if($ok) {
echo "<font face=verdana size=2>The file was successfully sent!</font>";
} else {
die("Sorry but the email could not be sent. Please go back and try again!");
}
?>
<p> </p>
</body>
</html>
-- phpMyAdmin SQL Dump
-- version 3.2.0.1
-- http://www.phpmyadmin.net
--
-- Serveur: localhost
-- Généré le : Jeu 01 Juillet 2010 à 15:56
-- Version du serveur: 5.1.36
-- Version de PHP: 5.3.0
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
--
-- Base de données: `sendfile`
--
-- --------------------------------------------------------
--
-- Structure de la table `tblmaster`
--
CREATE TABLE IF NOT EXISTS `tblmaster` (
`signature_data` varchar(255) CHARACTER SET utf8 NOT NULL,
`size` int(255) NOT NULL,
`ref_count` int(255) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
--
-- Contenu de la table `tblmaster`
--
-- --------------------------------------------------------
--
-- Structure de la table `tbluser`
--
CREATE TABLE IF NOT EXISTS `tbluser` (
`url` varchar(255) NOT NULL,
`signature` varchar(255) NOT NULL,
`filename` varchar(255) NOT NULL,
`content_file` varchar(255) NOT NULL,
`created` date NOT NULL,
`last_access` date NOT NULL,
`password` varchar(255) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
--
-- Contenu de la table `tbluser`
--
===================
gio làm thế nào để kết nối php vói database đó + cần những files php nhu thế nào bro help mình với.
Bro có thể liên lạc qua nick yahoo của mình để tiện trao dôi: gonewiththewind2512
<?php
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
die('Không kết nối được: ' . mysql_error());
}
echo 'Kết nối thành công<br>';
mysql_close($link);
?>
<?php
$my_mysql_host="localhost"; // localhost, or localhost:3006, or something else, which provide by hosting ISP to connect
$my_mysql_user="root"; // user to connect to mysql server, default: root
$my_mysql_password=""; // password to connect to mysql server, maybe blank
$my_db_name ="sendfile"; // database which created as in the readme file!
$db = mysql_connect($my_mysql_host,$my_mysql_user,$my_my sql_password);
mysql_select_db($my_db_name, $db);
?>
đây là code của mình; vấn đề gio minh gặp phải là không biết nên viết function addatachfile như thế nào: bacx cho goi ý mình chút dc ko?