PHP - Php Create Csv, Insert Into Db, Send Email With Attachment To A Bcc Address
I'm trying to after submission
1. create a csv
2. insert record into db
3. send email that's created in form submission - $msg.
4. send email with attachment to only the email I specify (if possible)
if not attach it to the email that's created at submission.
I've search and search and found different methods but doesn't work with my code.
I kept 3 lines at the top but can't get them to work ... either I don't get an email after submission or don't get an attachement.
Can some one help?
<?php $random_hash = md5(date('r', time())); $csvString = "..."; // your entire csv as a string $attachment = chunk_split(base64_encode($csvString)); $to = "email@email.com"; if(isset($_POST['submit'])) { // VALIDATION if(empty($_POST['firstName'])) { "First Name Required"; } if(empty($_POST['lastName'])) { "Last Name Required"; } if(empty($error)) { $to = "$to"; $subject = 'The Form'; $headers = "MIME-Version: 1.0 \r\n"; $headers .= "Content-Type: text/html; \r\n" ; $msg .="<html> <head></head> <body> <table width='100%' cellspacing='0' border='0' cellpadding='0'> <tr><td> <table width='100%' cellspacing='0' border='0' cellpadding='0'> <tr><td>This is the email sent.</td></tr> </table> </body> </html>"; include('con.php'); $con = mysqli_connect($host,$user,$pass,$dbName); if (!$con) { die('Could not connect: ' . mysqli_error($con)); } mysqli_select_db($con,"thetable"); $firstName = mysqli_real_escape_string($con, $_POST['firstName']); $lastName = mysqli_real_escape_string($con, $_POST['lastName']); $sql = "SELECT * FROM thetable WHERE `firstName` = '{$firstName}' OR `lastName` = '{$lastName}'"; $result = mysqli_query($con,$sql); if(($result->num_rows)>= 1) { $theerror = "You exist"; } else { $sql="INSERT INTO thetable(firstName, lastName) VALUES ('$_POST[firstName]','$_POST[lastName]'"; $success = "Sent ... Insert it!!!"; if (!mysqli_query($con,$sql)) { die('Error: ' . mysqli_error($con)); } $result = @mail($to, $subject, $msg, $headers); } mysqli_close($con); { } } } ?> Edited by barkly, 27 October 2014 - 02:59 PM. Similar TutorialsHi, I've created a basic form which uploads a document to my server. How do I generate an email with the uploaded document as an attachment? Here's the HTML: <form enctype="multipart/form-data" action="form1.php" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="100000" /> Choose a file to upload: <input name="uploadedfile" type="file" /><br /> <input type="submit" value="Upload File" /> </form> Here's the PHP: <?php $target_path = "uploads/"; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else{ echo "There was an error uploading the file, please try again!"; } ?> Thanks in advance! Interested to find out why this code doesn't seem to properly send the attachment.. it's driving my insane ? Code: [Select] <?php //define the receiver of the email $to = 'youraddress@example.com'; //define the subject of the email $subject = 'Test email with attachment'; //create a boundary string. It must be unique //so we use the MD5 algorithm to generate a random hash $random_hash = md5(date('r', time())); //define the headers we want passed. Note that they are separated with \r\n $headers = "From: webmaster@example.com\r\nReply-To: webmaster@example.com"; //add boundary string and mime type specification $headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\""; //read the atachment file contents into a string, //encode it with MIME base64, //and split it into smaller chunks $attachment = chunk_split(base64_encode(file_get_contents('attachment.zip'))); //define the body of the message. ob_start(); //Turn on output buffering ?> --PHP-mixed-<?php echo $random_hash; ?> Content-Type: multipart/alternative; boundary="PHP-alt-<?php echo $random_hash; ?>" --PHP-alt-<?php echo $random_hash; ?> Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Hello World!!! This is simple text email message. --PHP-alt-<?php echo $random_hash; ?> Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: 7bit <h2>Hello World!</h2> <p>This is something with <b>HTML</b> formatting.</p> --PHP-alt-<?php echo $random_hash; ?>-- --PHP-mixed-<?php echo $random_hash; ?> Content-Type: application/zip; name="attachment.zip" Content-Transfer-Encoding: base64 Content-Disposition: attachment <?php echo $attachment; ?> --PHP-mixed-<?php echo $random_hash; ?>-- <?php //copy current buffer contents into $message variable and delete current output buffer $message = ob_get_clean(); //send the email $mail_sent = @mail( $to, $subject, $message, $headers ); //if the message is sent successfully print "Mail sent". Otherwise print "Mail failed" echo $mail_sent ? "Mail sent" : "Mail failed"; ?> I would like to store PDF file into mysql (this part works) and then send it as email attachment and it should be retrieved from mysql table. Here's the code I have for now, but what it gives me is 0bytes large PDF file Saving PDF to mysql (it works), because size of blob in mysql table is OK. $fp = fopen('generated.pdf', 'r'); $content = fread($fp,filesize('generated.pdf')); $content = addslashes($content); fclose($fp); $DB->Query('insert into pdf_files (pdf_file, name) values ("'.$content.'", "'.$name.'")'); And here's the mailing part <?php $query = "SELECT name, pdf_file FROM pdf_files $result = mysql_query($query) or die(mysql_error()); while ($row = mysql_fetch_array ( $result)) { $fileContent =$row['pdf_file']; $fileName=$row['name']; } $fileatt = $fileContent; // getting file $fileatt_type ="application/pdf"; //type of file $fileatt_name = "attachment.pdf"; // name $fileatt_size = $fileSize; $email_from = "dont@have.it"; // mail from $email_subject = "Testtt"; // subject $email_message = "Testtt.<br>"; $email_message .= "Testtt.<br>"; // Message $email_to = $mail_user; // users mail $headers = "From: ".$email_from; $file = fopen($fileatt,'rb'); $data = fread($file,filesize($fileatt)); fclose($file); $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 .= "Testtt.\n\n" . "--{$mime_boundary}\n" . "Content-Type:text/html; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $email_message .= "\n\n"; $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"; $ok = @mail($email_to, $email_subject, $email_message, $headers); if($ok) { echo "<font face=verdana size=2><center>Mail was sent</center>"; } else { die("Error!"); } ?> I have made a shopping cart where I can add items from my sql table. But I dont know how to send the table to my email. this is my cart.php Can someone give me some tips? Thanks in advance. you can also check it out on http://fhcs.be/cart-demo3/ <?php // Include MySQL class require_once('inc/mysql.class.php'); // Include database connection require_once('inc/global.inc.php'); // Include functions require_once('inc/functions.inc.php'); // Start the session session_start(); // Process actions $cart = $_SESSION['cart']; $action = $_GET['action']; switch ($action) { case 'add': if ($cart) { $cart .= ','.$_GET['id']; } else { $cart = $_GET['id']; } break; case 'delete': if ($cart) { $items = explode(',',$cart); $newcart = ''; foreach ($items as $item) { if ($_GET['id'] != $item) { if ($newcart != '') { $newcart .= ','.$item; } else { $newcart = $item; } } } $cart = $newcart; } break; case 'update': if ($cart) { $newcart = ''; foreach ($_POST as $key=>$value) { if (stristr($key,'qty')) { $id = str_replace('qty','',$key); $items = ($newcart != '') ? explode(',',$newcart) : explode(',',$cart); $newcart = ''; foreach ($items as $item) { if ($id != $item) { if ($newcart != '') { $newcart .= ','.$item; } else { $newcart = $item; } } } for ($i=1;$i<=$value;$i++) { if ($newcart != '') { $newcart .= ','.$id; } else { $newcart = $id; } } } } } $cart = $newcart; break; } $_SESSION['cart'] = $cart; ?><!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>PHP Shopping Cart Demo &#0183; Cart</title> <link rel="stylesheet" href="css/styles.css" /> </head> <body> <div id="shoppingcart"> <h1>Your Shopping Cart</h1> <?php echo writeShoppingCart(); ?> </div> <div id="contents"> <h1>Please check quantities...</h1> <?php echo showCart(); ?> <p><a href="index.php">Back to bookshop...</a></p> </div> </body> </html> I am having trouble figuring out the right keywords to search for this, but what would I need to research if I want a user to send an email to a specific address (i.e. support@domain.com) and to have it create a new MySQL database entry, sort of like a help desk would generate? How to create a pdf dynamically and that pdf should sent as a email attachment.
can anyone please help me that i m a new user of PHP and linux so please tell me how i can send an email when mySQL insert trigger have been generated. the scenario is like this, that when new value insert in a table (client_Table), then insert trigger is generated and the functionality of that trigger is that it gets the last inserted row Primary ID (suppose the value is '111') and get the specific audio file (with the name of "111") from specific location in Linux path (/var/lib/audio/"TablePrimaryID".wav) and send Email with audio file attachment and primary ID, to any specific Mail address. (with the help of gmail SMTP). i wanting users to be able to update there email address and check to see if the new email already exists. if the email is the same as current email ignore the check. i have no errors showing up but if I enter a email already in the db it still accepts the new email instead of bringing the back the error message. Code: [Select] // email enterd from form // $email=$_POST['email']; $queryuser=mysql_query("SELECT * FROM members WHERE inv='$ivn' ") or die (mysql_error()); while($info = mysql_fetch_array( $queryuser )) { $check=$info['email']; // gets current email // } if($check!=$email){ // if check not equal to $email check the new email address already exists// $queryuser=mysql_query("SELECT * FROM members WHERE email='$email' "); //$result=mysql_query($sql); $checkuser=mysql_num_rows($queryuser); if($checkuser != 0) { $error= "0"; header('LOCATION:../pages/myprofile.php?id='.$error.''); } } cheers I have a form with PHP validation and also a mysqli query checking for duplicates in the database for mailing address and email address in mysql.
It works fine but the customers are adding spaces in the mailing address for example 111 mailing address A V E, 1 1 1 ma iling address A V E etc. and my sql query doesn't see that as an address that's a duplicate.
Their alslo adding email address like my@emailaddress.com and m.y@emailaddress.com, m.y.2@emailaddress.com etc to bypass that comparision also.
Is there anyway to stop this from happening?
hello, I did my first application of mailer php today, very nice, sending 2 pdf attachments, but for record keeping, I need a copy of the mail to go to another mail, but with out the attachments, how to accomplish this please?? here the code form html: Code: [Select] <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>Contact Form</title> <meta name="Generator" content="Alleycode HTML Editor"> <meta name="Description" content="Your description here..."> <meta name="Keywords" content="Your keywords here..."> </head> <body> <form method="post" action="sendmail2.php"> <p> <label>Name:</label> <br/> <input type="text" name="name" size="48" height="40"/> </p> <p> <label>Email:</label> <br/> <input type="text" name="email" size="48" height="40"/> </p> <p> <label>Child's Name:</label> <br/> <input type="text" name="childname" size="48" height="40"/> </p> <p> <label>Site:</label> <br/> <textarea name="site" rows="2" cols="45" overflow:hidden>xx.com.au</textarea> </p> <p> </p> <p> <label>Days:</label> <br/> <textarea name="days" rows="2" cols="45" overflow:hidden>Monday, Tuesday, Wednesday, Thursday, Friday</textarea> </p> <p> </p> <p> <input type="submit" value="Send"/> <a href="xx/form.html">clear</a></p> </form> </body> </html> sendmail2.php: <?php require("../phpmailer/class.phpmailer.php"); include("email.php"); $name = $_POST['name']; $childname = $_POST['childname']; $site = $_POST['site']; $days = $_POST['days']; $mail = new PHPMailer(); $mail->IsSMTP(); $mail->SMTPAuth = true; $mail->Host = "xxx.com"; // SMTP servers $mail->Username = "xxx"; // SMTP username $mail->Password = "xxx"; // SMTP password $mail->AddAddress($_POST['email']); $mail->From = "xxx@ax.com.au"; $mail->FromName = "xxx_online"; $mail->Subject = "Message from Alouette"; $mail->IsHTML(true); $mail->Body = $message; $mail->AddAttachment("../attachs/x.pdf"); $mail->AddAttachment("../attachs/xd.pdf"); if($mail->Send()) { echo "Message sent! Thanks ! "; print('<a href="xu/mail/form.html">Reset and Back</a>'); } ?> email.php <?php $message = ' Hello '.$name.', <br/> we have received your interest in child care services for '.$childname.' from the '.$site.' website. <br/> <br/> '.$days.' <br/> <br/> Should you have any questions regarding the information on our enrolment form or services please do not hesitate to contactkkk <br/> <br/> <br/> Regards, <br/> <a href="mailto:x@x.com.au">x@nx.com.au</a> <a href="http://www.nx.com.au" target="_new">www.neo-it.com.au</a> <br/> <strong>Childcare Management Services</strong> <br/> <br/> ' ?> i'm using a flash frontend, and i need help with a script that will take all the files in a folder (up to 6) and mail it to someone. i can do it as a zip or not. can anyone help please. This topic has been moved to Other Libraries and Frameworks. http://www.phpfreaks.com/forums/index.php?topic=314260.0 Hello, I am working with a SMTP class to send an email. It's all working perfectly fine, but when the email is received (sent from the online form), and I open my email and click reply, there are two email addresses. The correct one (which I entered when I sent the email), and my ftp username for the site?? I've got three files that could effect this, but I was unable to locate any problems: mailer.php ( smtp send mail class) mail.php ( submission data: title, subject, etc. ) contact_form.php ( form for submission ) I am only including the file which I think is applicable (mail.php), but let me know if you would also like to see the mailer.php class. Current output: reply-to ftpusername@domainname.com, correct_from_email@fromemail.com mail.php: <?php set_time_limit(120); function sendHTMLmail($from, $to, $subject, $message) { $message = wordwrap($message, 70); // To send HTML mail, the Content-type header must be set $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // Additional headers $headers .= "From: $from\r\n"; // Mail it mail($to, $subject, $message, $headers); } function sendHTMLmail2($fromid, $to, $subject, $message) { echo $fromid; echo $to; echo $subject; echo $message; include_once("mailer.php"); $mail = new PHPMailer(); $mail->IsMail(); // SMTP servers $mail->Host = "localhost"; $mail->From = $fromid; $mail->FromName = $fromid; $mail->IsHTML(true); $mail->AddAddress($to, $to); $mail->Subject = $subject; $mail->Body = $message; $mail->AltBody = "Please enable HTML to read this"; $mail->Send(); exit; } function isValidEmail($email) { return eregi("^[_.0-9a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,3}$", $email); } class smtp_mail { var $host; var $port = 25; var $user; var $pass; var $debug = false; var $conn; var $result_str; var $charset = "utf-8"; var $in; var $from_r; //mail format 0=normal 1=html var $mailformat = 0; function smtp_mail($host, $port, $user, $pass, $debug = false) { $this->host = $host; $this->port = $port; $this->user = base64_encode($user); $this->pass = base64_encode($pass); $this->debug = $debug; $this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); if ($this->socket) { $this->result_str = "Create socket:" . socket_strerror(socket_last_error()); $this->debug_show($this->result_str); } else { exit("Initialize Faild,Check your internet seting,please"); } $this->conn = socket_connect($this->socket, $this->host, $this->port); if ($this->conn) { $this->result_str = "Create SOCKET Connect:" . socket_strerror(socket_last_error()); $this->debug_show($this->result_str); } else { exit("Initialize Faild,Check your internet seting,please"); } $this->result_str = "Server answer:<font color=#cc0000>" . socket_read($this->socket, 1024) . "</font>"; $this->debug_show($this->result_str); } function debug_show($str) { if ($this->debug) { echo $str . "<p>\r\n"; } } function send($from, $to, $subject, $body) { if ($from == "" || $to == "") { exit("type mail address please"); } if ($subject == "") $sebject = "none title"; if ($body == "") $body = "none content"; $All = "From:$from;\r\n"; $All .= "To:$to;\r\n"; $All .= "Subject:$subject;\r\n"; if ($this->mailformat == 1) { $All .= "Content-Type:text/html;\r\n"; } else { $All .= "Content-Type:text/plain;\r\n"; } $All .= "Charset:" . $this->charset . ";\r\n\r\n"; $All .= " " . $body; $this->in = "EHLO HELO\r\n"; $this->docommand(); $this->in = "AUTH LOGIN\r\n"; $this->docommand(); $this->in = $this->user . "\r\n"; $this->docommand(); $this->in = $this->pass . "\r\n"; $this->docommand(); if (!eregi("235", $this->result_str)) { $this->result_str = "smtp auth faild"; $this->debug_show($this->result_str); return 0; } $this->in = "MAIL FROM: $from\r\n"; $this->docommand(); $this->in = "RCPT TO: $to\r\n"; $this->docommand(); $this->in = "DATA\r\n"; $this->docommand(); $this->in = $All . "\r\n.\r\n"; $this->docommand(); if (!eregi("250", $this->result_str)) { $this->result_str = "Send mail faild!"; $this->debug_show($this->result_str); return 0; } $this->in = "QUIT\r\n"; $this->docommand(); socket_close($this->socket); return 1; } function docommand() { socket_write($this->socket, $this->in, strlen($this->in)); $this->debug_show("Client command:" . $this->in); $this->result_str = "server answer:<font color=#cc0000>" . socket_read($this->socket, 1024) . "</font>"; $this->debug_show($this->result_str); } } ?> Hi, n0obie here. I'm trying to identify where my customers are coming from via emails I've sent/received. However, many email providers (namely Gmail) have circumvented this by disallowing IP address geolocation/image caching. Ive been trying to get this email attachment to work but I think one of the headers is wrong. It wont attach the file Code: [Select] $address = "mail@site.com"; $subject = "Test HTML Message"; $hash = md5(rand().time()); $headers .= "From: yourname <you@youremail.com>\r\nReply-To: noreply@youremail.com"; $headers .= "\nMIME-Version: 1.0\r\nContent-Type: multipart/mixed; boundary=\"bound-{$hash}\" "; $file = "http://www.site.com/images/funny.jpg"; $attachment = chunk_split(base64_encode(file_get_contents($file))); $ext = pathinfo($file, PATHINFO_EXTENSION); $file_base = pathinfo($file, PATHINFO_BASENAME); $body = " --bound-{$hash} Content-Type: text/html Content-Transfer-Encoding: 7bit <h2>Hello from Wizecho!</h2> <p>This is the actual email you will receive with <b>HTML</b> <i>formatting.</i></p> --bound-{$hash} Content-Type: image/jpeg name=\"{$file_base}\" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: attachment {$attachment} --bound-{$hash}-- "; if(mail($address,$subject,$body,$headers)){ echo "Email Sent"; }else{ echo "Mail not sent"; } I created a php file to send an email with two image attachments. The email portion sends the email o.k., but I can't get the attachments to load. The first is my form. <?php if(!empty($_POST)) { // The HTML form handler. require "handler.php"; } ?> <script type = "text/javascript"> //Validate required function validateRequired(FIELD, ALERTTEXT) { with(FIELD) { if(value == null || value == '') { alert(ALERTTEXT); return false; } else { return true; }; }; }; function validateForm(FORM) { with(FORM) { if(validateRequired( fName, "You must provide your First Name!") == false) {fName.focus(); return false;}; if(validateRequired( lName, "You must provide your Last Name!") == false) {lName.focus(); return false;}; if(validateRequired( job, "You must provide your Occupation!") == false) {job.focus(); return false;}; if(validateRequired( month, "You must provide your Birthday Month!") == false) {month.focus(); return false;}; if(validateRequired( day, "You must provide your Birthday Day!") == false) {day.focus(); return false;}; if(validateRequired( year, "You must provide your Birthday Year!") == false) {year.focus(); return false;}; if(validateRequired( city, "You must provide your City!") == false) {email.focus(); return false;}; if(validateRequired( state, "You must provide your State!") == false) {email.focus(); return false;}; if(validateRequired( phone, "You must provide your Phone Number!") == false) {email.focus(); return false;}; if(validateRequired( email, "You must provide your Email!") == false) {email.focus(); return false;}; //if(validateRequired( full, "You must provide a Full Body Photo!") == false) {full.focus(); return false;}; //if(validateRequired( hdst, "You must provide a Head Shot Photo!") == false) {hdst.focus(); return false;}; }; }; </script> <div id="form"> <p>STEP ONE:</p> <form name="contest" method="post" action="paypal.php" onsubmit="return validateForm(this)" enctype="multipart/form-data" style="margin-left:10px;" > <div id="aName"> First Name<span style="color:#F00;">*</span> <input type="text" name="fName" id="fName" style="width:150px;" /> Last Name<span style="color:#F00;">*</span> <input type="text" name="lName" id="lName" style="width:150px;" /> Occupation<span style="color:#F00;">*</span> <input type="text" name="job" id="job" style="width:150px;" /> </div> <div id="location"> Birthday<span style="color:#F00;">*</span> <input type="text" name="month" maxlength="2" id="month" style="width:30px;" /> / <input type="text" name="day" id="day" maxlength="2" style="width:30px;" /> / <input type="text" name="year" id="year" maxlength="2" style="width:30px;" /> City<span style="color:#F00;">*</span> <input type="text" name="city" maxlength="20" id="city" style="width:200px;" /> State<span style="color:#F00;">*</span> <input type="text" name="state" maxlength="2" id="state" style="width:30px;" /> Phone<span style="color:#F00;">*</span> <input type="text" name="phone" maxlength="14" id="phone" style="width:200px;" /> </div> <div id="con contact"> Email<span style="color:#F00;">*</span> <input type="text" name="email" id="email" style="width:200px;" /> Website <input type="text" name="web" id="web" style="width:200px;" /> Facebook <input type="text" name="facebook" id="facebook" style="width:200px;" /> </div> <div id="biog"> Why Should you be crowned Diva of the Year?<span style="color:#F00; font-size:12px;"> *Limit 350 words</span> <br /> <textarea name="bio" id="bio" cols="60" rows="10"></textarea> </div> <!--<div id="fileUpload"> <p style="color:#F00; font-style:italic; font-size:12px;">A picture with your application is required. A full length and headshot only. The image must be .jpg</p> Full Body Picture<span style="color:#F00;">*</span> <span style="color:#F00; font-size:12px;">(Max file size 2MB)</span> <br /> <input type="hidden" name="MAX_FILE_SIZE" value="102400" /> <input type="hidden" name="upload" value="upload" id="upload" > <input type="file" name="full" id="full" /> <br /> <br /> Head Shot Picture<span style="color:#F00;">*</span> <span style="color:#F00; font-size:12px;">(Max file size 2MB)</span> <br /> <input type="hidden" name="MAX_FILE_SIZE" value="102400" /> <input type="file" name="hdst" id="hdst" /> <input type="hidden" name="upload" value="upload" id="upload" > </div>--> <div id="marketing"> <input type="checkbox" name="news" id="news" checked="checked" /> Yes, Please sign me up to receive a monthly newsletter and other email from SizeSexyDivas </div> <div id="done"> <input type="submit" name="submit" value="Submit" id="submit" > </div> <div id="errorMessage"> <?php echo "<h3>". $error ."</h3>"; ?> </div> <span style="text-align:center; font-size:10px; color:#999;">For full contest "Rules and Regulations" on the SizeSexyDiva of the Year Contest Click <a href="rules.php" style="color:#900;">Here.</a></span> </form> </div> This is the function php on the handler.php page: <?php // Process form fields $fName = $_POST['fName']; $lName= $_POST['lName']; $job = $_POST['job']; $month = $_POST['month']; $day = $_POST['day']; $year = $_POST['year']; $age = ($month . " / " . $day . " / " . $year); $city = $_POST['city']; $location = ($city . ", " . $state); $state = $_POST['state']; $phone = $_POST['phone']; $email = $_POST['email']; $web = $_POST['web']; $facebook = $_POST['facebook']; $bio = $_POST['bio']; $bio = wordwrap($bio, 70); $news = $_POST['news']; $_POST['fName'] = htmlspecialchars(stripslashes($_POST['fName'])); $_POST['lName'] = htmlspecialchars(stripslashes($_POST['lName'])); $_POST['email'] = htmlspecialchars(stripslashes($_POST['email'])); $_POST['bio'] = htmlspecialchars(stripslashes($_POST['bio'])); $_POST['web']= htmlspecialchars(stripslashes($_POST['web'])); $_POST['facebook']= htmlspecialchars(stripslashes($_POST['facebook'])); $_POST['city']= htmlspecialchars(stripslashes($_POST['city'])); $_POST['state']= htmlspecialchars(stripslashes($_POST['state'])); $_POST['month']= htmlspecialchars(stripslashes($_POST['month'])); $_POST['day']= htmlspecialchars(stripslashes($_POST['day'])); $_POST['year']= htmlspecialchars(stripslashes($_POST['year'])); if($_SERVER['REQUEST_METHOD']=="POST") { //Add a multipart boundary above the plain message $to = 'Del*Nique Works <customerservice@delnique.com>'; $to = 'SizeSexyDivas <contest@sizesexydivas.com>'; $from = stripslashes($fName . " " . $lName . " at " . $email); $subject = "Contestant Application " .strftime("%T", time()); // generate a random string to be used as the boundary marker $mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x"; // Add the headers for a file attachment $head = "From: $from\n". "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; // here, we'll start the message body. this is the text that will be displayed in the e-mail $application = "SizeSexyDiva of the Year Contestant: $from\n\n"; $application .= " Name: $fName" . " " . "$lName \n Occupation: $job \n Location: $location \n Phone: $phone \n Age: $age \n Email: $email \n Website: $web \n Facebook: $facebook\n Newsletter: $news\n Full Body: $fdata\n Head Shot: $hdata\n Bio: $bio \n\n "; //next, we'll build the invisible portion of the message body *note that we insert two dashes in front of the MIME boundary when we use it $application = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $application ."\n\n"; //now we'll process our uploaded files foreach($_FILES as $userfile){ //store the file information to variables for easier access $tmp_name = $userfile['tmp_name']; $type = $userfile['type']; $name = $userfile['name']; $size = $userfile['size']; // if the upload succeded, the file will exist if (file_exists($tmp_name)) { // check to make sure that it is an uploaded file and not a system file if (is_uploaded_file($tmp_name)) { //open the file for a binary read the file to be attached ('rb' = read binary) $file = fopen($tmp_name,'rb'); // read the file content into a variable $data = fread($file,filesize($tmp_name)); // close the file fclose($file); // Base64 encode the file data for full and split it into acceptable length lines $data = chunk_split(base64_encode($data)); } $application .= "--{$mime_boundary}\n" . "Content-Type: {$type};\n" . " name=\"{$name}\"\n" . "Content-Disposition: attachment;\n" . " filename=\"{$fileatt_name}\"\n" . "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n"; } } // here's our closing mime boundary that indicates the last of the message $application .= "--{$mime_boundary}--\n"; //send mail function @mail( $to, $subject, $head, $application); ?> So if you can help me I would really appreciate it. Hi I need to attach a file to an email from my database records So far i have: function sendNewCandidate($user, $email, $agent, $jobtitle, $useremail, $cv) { $from = "From: ".$user." <".$useremail.">"; $subject = "New applicant"; $attachment = chunk_split(base64_encode(file_get_contents('http://www.website.co.uk/$cv'))); $body = $agent.",\n\n" ."".$user." has applied for your job ".$jobtitle."." ."We suggest you go to your admin panel and view the CV" ."- Thank you. "; return mail($email, $subject, $body, $from); } }; $cv holds the location of the file for the user. These files are generally .doc I have read i may need something like this: Content-Type: application/zip; name="attachment.zip" Content-Transfer-Encoding: base64 Content-Disposition: attachment but how would i incorporate this? Thanks guys Hi All, Is there a way we can write a PHP script to automatically read receive emails, extract csv file attachment from there and insert into MySQL database then run this in Cron Jobs to automate the process? |