In this example i developed a page through wich you can send a mail with one attached file from your webpage to a desired e-mail address. You attach the file from you harddrive. It can be developed so you can send more than one file or to more users. I'll maybe start to work on it if i'll have some spare time. :P This code is developed after "PHP Email Attachment v2 by Christoph2k". Thanks for your code, it really helped me out.
// 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";
<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 :D $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'];
$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 :D $fileatt_name = "CV".$_POST['nume']."_".$_POST['prenume'].".doc"; // Filename that will be used for the file as the attachment
/********************************************** 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>
DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.