PHP - Please Help Sending Email Attachments
Hi,
I have done this script that sends emails without attachments. What I want to do now is add the functionality to attach multiple files using one single field, kind of what Outlook does...you can select one or more files to attach to your email. Any ideas how I can do this? Thanks Code: [Select] <?php $EmailTo = Trim(stripslashes($_POST['to'])); $Subject = Trim(stripslashes($_POST['subject'])); $email = Trim(stripslashes($_POST['email'])); // 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: My company<info@mycompany.com>' . "\r\n"; $headers .= "Cc: {$_POST['cc']}\r\n"; $headers .= "Bcc: {$_POST['bcc']}\r\n"; // prepare email body text $Body = ""; $Body .= $email; $Body .= "\n"; $Body .= "\n"; // send email $success = mail($EmailTo, $Subject, stripslashes($Body), $headers); // redirect to success page if ($success){ print "<meta http-equiv=\"refresh\" content=\"0;URL=../PC_email_compose.php?emailsentok=true\">"; } else{ print "<meta http-equiv=\"refresh\" content=\"0;URL=../PC_email_compose.php?emailsenterror=true\">"; } ?> Similar TutorialsHey All, I am having issues understanding how this works. I am trying to do a quote and send out 5 images of the product. I cannot seem to get how I get the images sent with the email. If anyone can take a look I would greatly appreciate it. PHP <?php $email = $_POST ['email']; $quote = $_POST ['quote']; $item = $_POST ['item']; $inventory = $_POST ['inventory']; $category = $_POST ['category']; $manu = $_POST ['manu']; $model = $_POST ['model']; $condition = $_POST ['condition']; $dimension = $_POST ['dimension']; $desc = $_POST ['desc']; $skidprice = $_POST ['skidprice']; $unitprice = $_POST ['unitprice']; $totalprice = $_POST ['totalprice']; $img1 = $_POST ['img1']; $img2 = $_POST ['img2']; $img3 = $_POST ['img3']; $img4 = $_POST ['img4']; $img5 = $_POST ['img5']; //Get the uploaded file information $name_of_uploaded_file = basename($_FILES['uploaded_file']['name']); //get the file extension of the file $type_of_uploaded_file = substr($name_of_uploaded_file, strrpos($name_of_uploaded_file, '.') + 1); $size_of_uploaded_file = $_FILES["uploaded_file"]["size"]/1024;//size in KBs //Validations if($size_of_uploaded_file > $max_allowed_file_size ) { $errors .= "\n Size of file should be less than $max_allowed_file_size"; } //------ Validate the file extension ----- $allowed_ext = false; for($i=0; $i<sizeof($allowed_extensions); $i++) { if(strcasecmp($allowed_extensions[$i],$type_of_uploaded_file) == 0) { $allowed_ext = true; } } if(!$allowed_ext) { $errors .= "\n The uploaded file is not supported file type. ". " Only the following file types are supported: ".implode(',',$allowed_extensions); } //copy the temp. uploaded file to uploads folder $path_of_uploaded_file = $upload_folder . $name_of_uploaded_file; $tmp_path = $_FILES["uploaded_file"]["tmp_name"]; if(is_uploaded_file($tmp_path)) { if(!copy($tmp_path,$path_of_uploaded_file)) { $errors .= '\n error while copying the uploaded file'; } } // Always set content-type when sending HTML email $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n"; // More headers $headers .= 'From: All Food Equipment<sales@allfoodequip.com>' . "\r\n"; $headers .= "Message-ID: <".$now." sales@".$_SERVER['SERVER_NAME'].">\r\n"; $headers .= "X-Mailer: PHP v".phpversion()."\r\n"; $subject = "Your All Food Equip Quote"; $msg = " <!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\"> <html> <head><link href=\"http://www.allfoodequip.com/admin/quote/style.css\" rel=\"stylesheet\" type=\"text/css\"></head> <body> <div id=\"container\" style=\"width:960px; height:auto; margin:0 auto; border-right: 2px solid #666; border-left: 2px solid #666;\"> <div id=\"header\" style=\"background-image:url(http://www.allfoodequip.com/admin/quote/images/banner_bg.jpg); width:100%; height:149px;\"></div> <!--Closes header--> <div id=\"subHead\" style=\"background-image:url(http://www.allfoodequip.com/admin/quote/images/menu_bg.jpg); width:100%; height:42px;\"></div> <!--closes subHead--> <div class=\"contents\" style=\"background:#f2f1f1; padding-right: 25px; padding-left: 25px;\"> <h1 style=\"margin:0px;padding:10px 0 5px;font-size:18px;\">Your All Food Equipment Quote:</h1> <table width=\"700\" border=\"0\" class=\"table\" style=\"padding:0px 0px 15px;\"> <tr> <td width=\"119\">Quote #:......................................................... </td> <td width=\"208\">$quote</td> </tr> <tr> <td>Item:..............................................................</td> <td>$item</td> </tr> <tr> <td>Inventory:.......................................................</td> <td>$inventory</td> </tr> <tr> <td>Category:.......................................................</td> <td>$category</td> </tr> <tr> <td>Manufacturer:.................................................</td> <td>$manu</td> </tr> <tr> <td>Model:...........................................................</td> <td>$model</td> </tr> <tr> <td>Condition:......................................................</td> <td>$condition</td> </tr> <tr> <td>Dimension:....................................................</td> <td>$dimension</td> </tr> <tr> <td>Description:...................................................</td> <td>$desc</td> </tr> <br> <tr> <td><b>Skid Price:</b>.................................................</td> <td><b>$skidprice</b></td> </tr> <tr> <td><b>Unit Price:</b>.................................................</td> <td><b>$unitprice</b></td> </tr> <tr> <td><b>Total Price:</b>................................................</td> <td><b>$totalprice</b></td> </tr> </table> <div class=\"t_middle\"> <img name=\"Img\" src=\"$img1\" width=\"177\" height=\"115\" alt=\"Img\" style=\"background-color: #999999\"><img name=\"Img\" src=\"$img2\" width=\"177\" height=\"115\" alt=\"Img\" style=\"background-color: #999999\"><img name=\"Img\" src=\"$img3\" width=\"177\" height=\"115\" alt=\"Img\" style=\"background-color: #999999\"><img name=\"Img\" src=\"$img4\" width=\"177\" height=\"115\" alt=\"Img\" style=\"background-color: #999999\"><img name=\"Img\" src=\"$img5\" width=\"177\" height=\"115\" alt=\"Img\" style=\"background-color: #999999\"> </div> <div class=\"break\" style=\"padding: 15px 0px; width:100%;\"><hr></div> <!--break--> <!--close t_middle--> <div class=\"contactUs\"> <p style=\"color:#650035;\">How to contact us:</p> <ul class=\"contact_list\" style=\"margin:0px;padding:0px;color:#650035;line-height:25px;padding-bottom:30px;list-style:none;\"> <li>Visit us Online: www.allfoodequip.com</li> <li>Contact: Dino Roberts</li> <li>Direct Line: 615-788-2953 </li> <li>Email: dino@allfoodequip.com</li> </ul> <ul class=\"contact_list\" style=\"margin:0px;padding:0px;color:#650035;line-height:25px;padding-bottom:30px;list-style:none;\"> <li>All Food Equipment</li> <li>1240 Industrial Park Road</li> <li>Columbia, TN 38401</li> <li>Main Office: 931-490-1977</li> </ul> </div> <p style=\"font-size:14px;color:#333;\">TERMS & CONDITIONS: </p> </div> <!--close m_disc--> <div id=\"footer\" style=\"clear: both; width: 100%; padding: 20px 0 20px 0; text-align: center; border-top: 1px solid #8b8a8b; background: #343233 url(http://www.allfoodequip.com/admin/quote/images/footer.jpg) no-repeat;\"> <ul class=\"footer_list\" style=\"margin:0px;padding:0px;list-style:none;\"> <li style=\"padding: 0 10px; display: inline; border-right: 1px solid #cccccc;\"><a href=\"http://www.allfoodequip.com\" style=\"color: #cccccc; text-decoration: none;\">Home</a></li> <li style=\"padding: 0 10px; display: inline; border-right: 1px solid #cccccc;\"><a href=\"http://www.allfoodequip.com/new-equipment.php\" style=\"color: #cccccc; text-decoration: none;\">New Equipment</a></li> <li style=\"padding: 0 10px; display: inline; border-right: 1px solid #cccccc;\"><a href=\"http://www.allfoodequip.com/used-equipment.php\" style=\"color: #cccccc; text-decoration: none;\">Used Equipment</a></li> <li style=\"padding: 0 10px; display: inline; border-right: 1px solid #cccccc;\"><a href=\"http://www.allfoodequip.com/services.php\" style=\"color: #cccccc; text-decoration: none;\">Services</a></li> <li style=\"padding: 0 10px; display: inline; border-right: 1px solid #cccccc;\"><a href=\"http://www.allfoodequip.com/about-us.php\" style=\"color: #cccccc; text-decoration: none;\">About Us</a></li> <li class=\"last\" style=\"padding:0 10px;display:inline;border-right:none;\"><a href=\"http://www.allfoodequip.com/contact-us.php\" style=\"color: #cccccc; text-decoration: none;\">Contact Us</a></li> </ul> <div class=\"margin_bottom_10\"></div><br> <span style=\"color:#FFF;\">Copyright © 2010 </span> - <a href=\"http://www.allfoodequip.com\"><font color=\"#FFFFCC\">All Food Equipment</font></a> <div class=\"margin_bottom_10\"></div> <!-- end of footer --> </div> <!--container--> </div> </body> </html> "; // MAIL SUBJECT $subject = "Your All Food Equip Quote"; // TO MAIL ADDRESS $to="$email"; mail($to, $subject, $msg, $headers); // Redirect header("Location: Admin.php?Msg=Sent"); ?> Heres the HTML side of it. Code: [Select] <label for="img1">Image 1:</label> <input type="hidden" name="MAX_FILE_SIZE" value="2500000"> <input type="file" name="img1"> <label for="img2">Image 2:</label> <input type="hidden" name="MAX_FILE_SIZE" value="2500000"> <input type="file" name="img2"> <label for="img3">Image 3:</label> <input type="hidden" name="MAX_FILE_SIZE" value="2500000"> <input type="file" name="img3"> <label for="img4">Image 4:</label> <input type="hidden" name="MAX_FILE_SIZE" value="2500000"> <input type="file" name="img4"> <label for="img5">Image 5:</label> <input type="hidden" name="MAX_FILE_SIZE" value="2500000"> <input type="file" name="img5"><br /> Thanks in advance. Hi all Im sending a dynamic created pdf file with php. It gets flagged as spam are things that can be done to help prevent this ? didnt really know where to post it. Hello, I'm trying to send an email with a PDF attachment. The email is sending, but the attachment will not open. Any help you can give is appreciated. Code snippets below: function mail_attachment($filename, $path, $mailto, $from_mail, $from_name, $replyto, $subject, $message) { $file = $path.$filename; $file_size = filesize($file); $handle = fopen($file, "r"); $content = fread($handle, $file_size); fclose($handle); $content = chunk_split(base64_encode($content)); $uid = md5(uniqid(time())); $name = basename($file); $header = "From: ".$from_name." <".$from_mail.">\r\n"; $header .= "Reply-To: ".$replyto."\r\n"; $header .= "MIME-Version: 1.0\r\n"; $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n"; $header .= "This is a multi-part message in MIME format.\r\n"; $header .= "--".$uid."\r\n"; $header .= "Content-type:text/plain; charset=iso-8859-1\r\n"; $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n"; $header .= $message."\r\n\r\n"; $header .= "--".$uid."\r\n"; $header .= "Content-Type: application/pdf; name=\"".$filename."\"\r\n"; // use different content types here $header .= "Content-Transfer-Encoding: base64\r\n"; $header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n"; $header .= $content."\r\n\r\n"; $header .= "--".$uid."--"; if (mail($mailto, $subject, "", $header)) { print("mail send ... OK"); // or use booleans here } else { print("mail send ... ERROR!"); } } $my_file = "Adol_Packet_v2.pdf"; $my_path = $_SERVER['DOCUMENT_ROOT']."/homepages/35/d350375870/htdocs/html/"; $my_name = "Company Name"; $my_mail = "atheneris@yahoo.com"; $my_replyto = "atheneris@yahoo.com"; $my_subject = "Welcome Email From Carlock & Associates"; $my_message = "Test Message"; mail_attachment($my_file, $my_path, $email_to, $my_mail, $my_name, $my_replyto, $my_subject, $my_message); I found the below code so I can attach a file to a email message, but there is a small problem I need some help with. The script works beautifully except for the fact that when message is received the attached file does not contain a file extension. I am able to open the attachment but I am receiving the windows dialog box that asks: "Choose the program you want to open this file". I intend on only using this script to attach HTML files so I am wondering if there is a way to make the file extension of the attachment read as .html? That way when the user receives the attachment it will automatically open with there default browser. Code: [Select] <?php $to = "test@test.com"; $from = "test@test.com"; $subject = "AHC"; $message = "hello world"; $fileatt = $_SERVER['DOCUMENT_ROOT']."/home-care-information/test.html"; $fileatt_type = "multipart/alternative"; //This is where the problem is I think $fileatt_name = "Application"; $headers = "From: $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}\""; $message = "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" . $message . "\n\n"; $data = chunk_split(base64_encode($data)); $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($to, $subject, $message, $headers); if ($ok) { echo "<p>Mail sent! Yay PHP!</p>"; } else { echo "<p>Mail could not be sent. Sorry!</p>"; } ?> Hi all First, thanks for any help you can offer! What I'm trying to do is have a form, when submitted, create an attachment (the attachment appends the form values if it is already created) AND send the form values to myself as well as the person filling in the form (so to the email address in the 'email' field). I have several php files that do everything except I cant get it to email to the address in the email field and I cant see where I'm going wrong. I am NOT very php literate and these files were created for me although I understand how they work mostly. Thanks! FridgeForm.html code: Code: [Select] <form onclick="return checkFields();" method="post" action="formsubmit.php" id="skopefridge" name="skopefridge" enctype="multipart/form-data"> <p align="right" class="style1 style2"><img src="skope_logo.png" width="235" height="38" border="0">JOB SHEET</p> <table BORDER=0 RULES=NONE FRAME=BOX cellspacing="2" cellpadding="7"> <tr> <td colspan="2"><strong>Request ID</strong> <input name="requestid" type="text" class="fieldwidth" id="firstname" maxlength="50" readonly style="background-color:#CCC"> </label> <strong>Operator Name</strong> <input name="operator" type="text" id="operator" size="20" maxlength="80"></td> <td colspan="3"><strong>Date & Time: </strong> <script type="text/javascript" src="time.js"></script></td> </tr> <tr> <td colspan="5"><strong>CALLERS DETAILS</strong></td> </tr> <tr> <td>Name</td> <td><input name="name" type="text" size="50" tabindex=1></td> <td>Night Phone</td> <td colspan="2"><input name="nightph" type="text" size="50" tabindex=5></td> </tr> <tr> <td>Street</td> <td><input name="street" type="text" size="50" tabindex=2></td> <td>Day Phone </td> <td colspan="2"><input name="dayph" type="text" size="50" tabindex=6></td> </tr> <tr> <td>Suburb</td> <td><input name="suburb" type="text" size="50" tabindex=3></td> <td>Mobile</td> <td colspan="2"><input name="mobile" type="text" size="50" tabindex=7></td> </tr> <tr> <td>City</td> <td><select name="selectcity" size="1" tabindex=4> <option value="Alexandra">Alexandra</option> <option value="Ashburton">Ashburton</option> <option value="Auckland">Auckland</option> <option value="Blenheim">Blenheim</option> <option value="Canterbury">Canterbury</option> <option value="Cromwell">Cromwell</option> <option value="Dannevirke">Dannevirke</option> <option value="Dargaville">Dargaville</option> <option value="Dunedin">Dunedin</option> <option value="Fiordland">Fiordland</option> <option value="Gisborne">Gisborne</option> <option value="Gore c/o Invercargill">Gore c/o Invercargill</option> <option value="Greymouth">Greymouth</option> <option value="Hamilton">Hamilton</option> <option value="Hastings">Hastings</option> <option value="Invercargill">Invercargill</option> <option value="Kerikeri">Kerikeri</option> <option value="Masterton">Masterton</option> <option value="Napier">Napier</option> <option value="Nelson">Nelson</option> <option value="New Plymouth">New Plymouth</option> <option value="Oamaru">Oamaru</option> <option value="Palmerston North">Palmerston North</option> <option value="Queenstown">Queenstown</option> <option value="Ranfurly">Ranfurly</option> <option value="Rotorua">Rotorua</option> <option value="Taupo">Taupo</option> <option value="Tauranga/ mt maunganui">Tauranga/ mt maunganui</option> <option value="Timaru">Timaru</option> <option value="Wanaka">Wanaka</option> <option value="Wanganui">Wanganui</option> <option value="Wellington">Wellington</option> <option value="Westport">Westport</option> <option value="Whakatane">Whakatane</option> <option value="Whangerei">Whangerei</option> <option value="test">test</option> <option value="test2">test2</option> </select></td> <td>Company</td> <td colspan="2"><input name="company" type="text" size="50" id="company" tabindex=8></td> </tr> <tr> <td colspan="5"><strong>PRODUCT DETAILS</strong></td> </tr> <tr> <td>Model</td> <td><input name="model" type="text" size="50" tabindex=9></td> <td>Purchased From </td> <td colspan="2"><input name="purchfrom" type="text" size="50" tabindex=11></td> </tr> <tr> <td>Serial No</td> <td><input name="serial" type="text" size="50" tabindex=10></td> <td>Date Purchased </td> <td colspan="2"><input name="datepurch" type="text" size="50" tabindex=12></td> </tr> <tr> <td> </td> <td> </td> <td>Proof Of Purchase? </td> <td colspan="2"><input name="proofpurch" type="text" size="50" tabindex=13></td> </tr> <tr> <td>Room Heater Installed In </td> <td colspan="4"><input name="installed" type="text" size="50" tabindex=14></td> </tr> <tr> <td>Heater Problem </td> <td colspan="4"><input name="problem" type="text" size="50" tabindex=15></td> </tr> <tr> <td colspan="5" align="center"><span class="style4">FOR ANY PROBLEMS/ENQUIRIES PLEASE CONTACT SKOPE INDUSTRIES PH:0800 947 5673</span> </td> </tr> <tr> <td colspan="5" align="center"><hr> <strong>Contact Belinda at Skope Services if the complete heater needs to be replaced. | Replaced parts are to be kept for 3 months. <br> <font color="#FF0000">This form is automatically emailed to the contractor associated with the city you choose above. The contractors details are below (for the chosen city) if you need to contact them)</font></strong> </td> </tr> </table> <table border="0" cellspacing="4" cellpadding="4"> <tr> <td>Contractor</td> <td style="display:none;">City</td> <td>Address</td> <td>Phone</td> <td>Fax</td> <td>Email</td> </tr> <tr> <td><input type="text" name="contractor" id="contractor" readonly style="background-color:#CCC"></td> <td style="display:none;"><input type="text" name="city" id="city" readonly style="background-color:#CCC"></td> <td><input type="text" name="address" id="address" readonly style="background-color:#CCC"></td> <td><input type="text" name="phone" id="phone" readonly style="background-color:#CCC"></td> <td><input type="text" name="fax" id="fax" readonly style="background-color:#CCC"></td> <td><input type="text" name="email" id="email" readonly style="background-color:#CCC"></td> </tr> </table> <p> <input type="submit" name="Submit" value="Submit" style="width:1000px; height:30px; "> </p> </form> formsubmit.php: <?php include ('../tools/maketable.php'); include ('../tools/processing.php'); $config = "skopeGlobal.php"; /****************************************************************/ /*FORM SUBMITTED DATA */ /****************************************************************/ // These are the fields that are posted from the form to be changed to suit the form // Make sure that there is one variable per form field or you may miss data $requestid = $_REQUEST["requestid"]; $operator = $_REQUEST["operator"]; $name = $_REQUEST["name"]; $street = $_REQUEST["street"]; $suburb = $_REQUEST["suburb"]; $selectcity = $_REQUEST["selectcity"]; $nightph = $_REQUEST["nightph"]; $dayph = $_REQUEST["dayph"]; $mobile = $_REQUEST["mobile"]; $company = $_REQUEST["company"]; $model = $_REQUEST["model"]; $serial = $_REQUEST["serial"]; $purchfrom = $_REQUEST["purchfrom"]; $datepurch = $_REQUEST["datepurch"]; $proofpurch = $_REQUEST["proofpurch"]; $installed = $_REQUEST["installed"]; $problem = $_REQUEST["problem"]; $email = $_REQUEST["email"]; $callerInfo = "Request ID=".$requestid."; Operator=".$operator."; Name=".$name."; Street=".$street."; Suburb=".$suburb."; City=".$selectcity."; Night Phone=".$nightph."; Day Phone=".$dayph."; Mobile Phone=".$mobile."; Company Name=".$company."; Model=".$model."; Serial No=".$serial."; Purchased From=".$purchfrom."; Date Purchased=".$datepurch."; Proof of Purchase=".$proofpurch."; Room Installed In=".$installed."; Product Problem=".$problem."; Emailed To=".$email; $display .= makeTable("Call Details",$callerInfo,1); processData($config,$display,$callerInfo); ?> skopeGlobal.php: <?php $title = "Skope Fridge Form"; //TODO: The title should be changed to a significant title $stylesheet = "http://www.thecallcentre.co.nz/css/submittedstyling.css"; // TODO: This Has to be changed to a stylesheet for the site // this must be a url or email will not style correctly $logo = "http://www.thecallcentre.co.nz/other/tcclogo.jpg"; $fileName="Skope-FridgeFormResults.xls"; $emailTo= $_REQUEST["email"]; $emailFrom="info@thecallcentre.co.nz"; $redirect="Thankyou.html"; ?> There are also other processing files but I'm not sure if you need to see their code or not. hi there. this is my first post. i'm sory for my english (i'm portuguese) i have i very bad situation. on my code. i'm sending an email from my aplication and when arrives to the client the Attachments is send with the extension ".dat". in my pc the email is sent correct. but from other pc (server) the extension arrives ".dat". does anyone have the same problem ??? please help me. tnks Hi all, Does anyone know how to extract attachments from an email that has more than one attachment associated with it? Getting the overall attachment data works fine using Code: [Select] <?php $attachment_data = imap_fetchbody($inbox,$email_number,2); ?> ..but breaking up that data into its component attachments is eluding me, and I can't find anything on the PHP doco that enabled me to do it. All info appreciated, WoolyG Hello I have a database table containing users uploaded word docs as long blobs (I know in an ideal world these should be in a filesystem, not a table but that wasn't possible) I'd like to be able to generate an email with php and send out these files as attachments. I have pear mail installed and can get this to send out emails with attachments form a file share no problems. Getting it to work with blobs escapes me though. Is this possibile of do I need a different class? Code: [Select] include('../db_connection.php'); $query1 = "SELECT id, name, type, content, size FROM upload WHERE lref='" . $_POST['lref'] . "'"; $result2 = $mysqlilsr->query($query1) or die ($mysqlilsr->error); list($id, $name, $type, $content, $size) = $result2->fetch_array(); //echo $name . '<br/>'; //echo $content . '<br/>'; //echo $type . '<br/>'; //$fileattname = file_get_contents($_POST['attachment']); $fileattname = file_get_contents($_POST['attachment']); $from_mail = "email address"; $replyto = "email address"; //phpinfo(); //mail_attachment($filename, $path, $mailto, $from_mail, $from_name, $replyto, $subject, $message); $headers = array( 'From' => $from_mail, 'Subject' => $subject, 'Cc' => $replyto, ); $body = $header . $spacer .$message . $spacer . $footer; $mime = new Mail_mime(); $mime->setTXTBody($body); $mime->addAttachment(base64_encode($content), $name, $type, "iso-8859-1"); $body = $mime->get(); $headers = $mime->headers($headers); $mailer =& Mail::factory('mail'); $res = $mailer->send($_POST['email'], $headers, $body); if (PEAR::isError($res)) { echo 'error'; } else { 'success'; } Hi all I'm trying to send an automated email of a zip file. However it seems to be just reading the files into the body of the mail rather than attaching a single zip archive containing several files. I receive the mails, but I effectively want a blank message body with a zip file attached. Please see code below, any ideas why this is not working. I'm a bit of a newbie and never used this before so any pointers would be good. <?php //Send Zip file as attachment //Set Email and attachment details $to = "me@123.com"; $from = "Visionnet <DO_NOT_REPLY>"; $subject = "Subject"; $message = "Please see attached file"; $fileatt = "wiki_zip.zip"; $fileatt_type = "application/zip"; $fileatt_name = "wiki_zip.zip"; //Read in the attachment $file=fopen($fileatt,'rb'); $data=fread($file,filesize( $fileatt)); fclose($file); //Add the MIME content $semi_rand = md5(time()); $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; // Add the Headers for file attachment $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; $message = "This is a multipart message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n"; //Base64 encode file data $data = chunk_split(base64_encode($data)); //Add attachment to message $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"; //Send message $ok = @mail($to, $subject, $message, $headers, "$from"); if($ok) { echo "mail sent"; } else { echo "mail failed"; } ?> I am piping email to a php script, from the email I want to get the email attachment that came with it. For our sake, the curent attachment I am working with is jpg. how can I get an image that is base64 encoded, then save it to a jpg file? "Content-Transfer-Encoding: base64" Just as the title says. In cPanel, I have it al configured just fine; the script recieves the email, and I do receieve an email back, but here's where I come into problems. It simply will NOT save the attachments to the server, I've tried loads of different implementations I've found, and nothing's working. pipe script: #!/usr/local/bin/php <?php // Need PEAR installed include('Mail.php'); include('Mail/mime.php'); require_once 'Mail/mimeDecode.php'; // read email using stdin $fx = fopen("php://stdin", "r"); $email = ""; while (!feof($fx)) { $email .= fread($fx,1024); } $params['include_bodies'] = true; $params['decode_bodies'] = true; $params['decode_headers'] = true; $params['input'] = $email; /* $message=new Mail_mimeDecode(); $mailObj=$message->decode($params); */ $mailObj = Mail_mimeDecode::decode($params); // Who is it from $from=$mailObj->headers['from']; // Get Subject $subj=$mailObj->headers['subject']; // Get Message Body $body=$mailObj->parts[0]->body; $gather="From:$from\nSubject:$subj\nBody:$body"; // Get and Save the Attachments foreach($mailObj->parts as $pp){ if ($pp->disposition=='attachment'){ $tmp=$pp->d_parameters['filename']; if($tmp !== ""){ $open = fopen($tmp, 'w'); if($open){ $write = fwrite($open,$pp->body); if(!$write){ $err = "Cannot write to file: '".$tmp."' - var: ".$write; } }else{ $err = "Cannot create/open file: '".$tmp."' - var: ".$open; } } } } $tox = $from; $subjectx = 'Your Photo was Uploaded!'; $messagex = $err; $headersx = 'From: piculo.us Uploader <upload@piculo.us>' . "\r\n" . 'Reply-To: upload@piculo.us' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($tox, $subjectx, $messagex, $headersx); exit; ?> Here's the email I get back: Cannot create/open file: '2879_1150712806251_1180540351_425140_7940412_n.jpg' - var: as you can see, it is aware that an attachment exists, but it won't create the file, and fopen() doesn't say anything. Any ideas?? I have a script that generates an excel spreadsheet, and attaches it to an email ready for mailing. Now, I can make it email the attachment no problem. I have searched for solutions on inserting 3 images in the email as well, but to no avail. I found a script that I thought could work, but it just sends the script via email and nothing else. Does anybody know of a good way to do this? Perhaps someone can help me with this script? <?php include "get_contact_list.php"; ################################################################################ ########### ### An email script that will attach images inline in an HTML and plain text e-mail ### ### Just enter you own email infomation and file names with paths where indicated in ### ### the script. Have fun with it alter it add to it or whatever you want. When you are ### ### done reading all the confusing tutorials about this kind of using mail to send your ### ### own without PHPmailer then you can just use this file to suit your self. ### ################################################################################ ########### $to = 'xxxxxxx@xxxxx.com';// same as above $subject = 'CONTACT & SUPERVISORS LIST_'.$date;//your own stuff goes here // Create a boundary string. It needs to be unique $random_hash = sha1(date('r', time())); // Add in our content boundary, and mime type specification: $headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\""; // Read in our file attachment $attachment = file_get_contents($path); $encoded = base64_encode($attachment); $attached = chunk_split($encoded); // additional headers $headers = "From: Nxxxxxx Cxxxxxx <xxxxxxxx@xxxxx.com>" . "\r\n" . 'Reply-To: xxxxxxxx@xxxxx.com' . "\r\n";//put you own stuff here or use a variable $inline = chunk_split(base64_encode(file_get_contents('../../images/emails/vcelogo.jpg'))); // Your message he ob_start();?> --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 Hai, Its me! --PHP-alt-<?php echo $random_hash; ?>-- Content-Type: multipart/related; boundary="PHP-related-<?php echo $random_hash; ?>--" --PHP-alt-<?php echo $random_hash; ?>-- Content-Type: text/html <html> <head> <title>Test HTML Mail</title> </head> <body> <font color='red'>Hai, it is me!</font> Here is my pictu <img src="cid:PHP-CID-<?php echo $random_hash; ?>" /> </body> </html> --PHP-related-<?php echo $random_hash; ?>-- Content-Type: image/jpeg; Content-Transfer-Encoding: base64 Content-ID: <PHP-CID-<?php echo $random_hash; ?>--> <?php echo $inline; ?> --PHP-related-<?php echo $random_hash; ?>-- --PHP-alt-<?php echo $random_hash; ?>-- --PHP-mixed-<?php echo $random_hash; ?>-- Content-Type: application/vnd.ms-excel; name='CONTACT & SUPERVISORS LIST_'.$date.'.xls'; Content-Transfer-Encoding: base64 Content-Disposition: attachment <?php echo $attachment; ?> --PHP-mixed-<?php echo $random_hash; ?>-- <?php $body = ob_get_clean(); // Finally, send the email $send = mail($to, $subject, $body, $headers); if ($send) { unlink($path); header("Location: hr_options.php?message=Sent successfully"); } else { header("Location: hr_options.php?message=Failed Sending"); } ?> From our website we are connecting to GMAIL to send our emails through SMTP. For some reason it is not sending the emails to the CC or BCC email address event though GMAIL shows it was included in the email. Am I missing something in the below code? Code: [Select] $currentTime = time(); $emailTo = "redbrad0@domain.com"; $emailCC = "brad@domain.com"; $emailBCC = "events@domain.com"; $emailSubject = "TEST Email at (" . $currentTime . ")"; $emailBody = "This is the body of the email"; $headers = array(); if (!empty($emailTo)) $headers['TO'] = $emailTo; if (!empty($emailCC)) $headers['CC'] = $emailCC; if (!empty($emailBCC)) $headers['BCC'] = $emailBCC; if (!empty($emailSubject)) $headers['Subject'] = $emailSubject; $headers['From'] = "events@domain.com"; $mime = new Mail_mime("\n"); $mime->setTXTBody($emailBody); $body = $mime->get(); $headers = $mime->headers($headers); $mail = Mail::factory('smtp', array ('host' => 'ssl://smtp.gmail.com', 'auth' => true, 'port' => 465, 'username' => 'events@domain.com', 'password' => 'thepasswordhere')); try { $result = $mail->send($emailTo, $headers, $emailBody); } catch (TixException $ex) { echo "<font color=red>Error:" . $ex->getCode() . "</font><br>"; } echo "Emailed at (" . $currentTime . ")<br>"; die; This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=348632.0 Everything about the email is sending except the message text does anyone know what the issue could be? here is the block of code that sends the email Thanks in advance Code: [Select] $image = "http://www.visualrealityink.com/dev/clients/arzan/snell_form/images/email.png"; echo "got to process form"; $target_path = "upload/"; $path = $target_path = $target_path . basename( $_FILES['file']['name']); $boundary = '-----=' . md5( uniqid ( rand() ) ); $message .= "Content-Type: application/msword; name=\"my attachment\"\n"; $message .= "Content-Transfer-Encoding: base64\n"; $message .= "Content-Disposition: attachment; filename=\"$path\"\n\n"; echo $path; $fp = fopen($path, 'r'); do //we loop until there is no data left { $data = fread($fp, 8192); if (strlen($data) == 0) break; $content .= $data; } while (true); $content_encode = chunk_split(base64_encode($content)); $message .= $content_encode . "\n"; $message .= "--" . $boundary . "\n"; $message .= $image . "<br />" . $_POST['name'] . "submitted a resume on our website. Please review the applications and contact the candidate if their resume is a fit for any open opportunities with the company. <br><br> Thank you. <br><br> SEI Team"; $headers = "From: \"Me\"<me@example.com>\n"; $headers .= "MIME-Version: 1.0\n"; $headers .= "Content-Type: multipart/mixed; boundary=\"$boundary\""; mail('george@visualrealityink.com', 'Email with attachment from PHP', $headers, $message); Hi the user fill details and then the email his sent to me the only problem is that the emails keeps going to my spam, can someone help me out please I looked already php website and email format looks the same. This is the link to my form. http://www.people.eurico.co.uk/ here my form script Code: [Select] <?php // Set email variables $email_to = 'xxxxx@xxxxxxx.co.uk'; $email_subject = 'Call back form'; // Set required fields $required_fields = array('fullname','email','telephone','comment'); // set error messages $error_messages = array( 'fullname' => 'Please enter a Name to proceed.', 'email' => 'Please enter a valid Email.', 'telephone' => 'Please telephone.', 'comment' => 'Please enter your Message to continue.' ); // Set form status $form_complete = FALSE; // configure validation array $validation = array(); // check form submittal if(!empty($_POST)) { // Sanitise POST array foreach($_POST as $key => $value) $_POST[$key] = remove_email_injection(trim($value)); // Loop into required fields and make sure they match our needs foreach($required_fields as $field) { // the field has been submitted? if(!array_key_exists($field, $_POST)) array_push($validation, $field); // check there is information in the field? if($_POST[$field] == '') array_push($validation, $field); // validate the email address supplied if($field == 'email') if(!validate_email_address($_POST[$field])) array_push($validation, $field); } // basic validation result if(count($validation) == 0) { // Prepare our content string $email_content = 'peoplesmartlearning.co.uk: ' . "\n\n"; // simple email content foreach($_POST as $key => $value) { if($key != 'submit') $email_content .= $key . ': ' . $value . "\n"; } // if validation passed ok then send the email mail($email_to, $email_subject, $email_content); // Update form switch $form_complete = TRUE; } } function validate_email_address($email = FALSE) { return (preg_match('/^[^@\s]+@([-a-z0-9]+\.)+[a-z]{2,}$/i', $email))? TRUE : FALSE; } function remove_email_injection($field = FALSE) { return (str_ireplace(array("\r", "\n", "%0a", "%0d", "Content-Type:", "bcc:","to:","cc:"), '', $field)); } ?> The HTML Code: [Select] <div class="call_us_form"> <p class="title">WE'LL CALL YOU BACK</p> <?php if($form_complete === FALSE): ?> <form class="contact_form" id="fm-form" method="post" action="index.php" > <fieldset> <div class="fm-req"> <label for="fm-firstname">Name</label> <input type="text" id="fullname" class="detail" name="fullname" value="<?php echo isset($_POST['fullname'])? $_POST['fullname'] : ''; ?>" /> <?php if(in_array('fullname', $validation)): ?><script type="text/javascript">alert("Please enter a Name"); history.back();</script><?php endif; ?> </div> <div class="fm-req"> <label for="fm-firstname">Email</label> <input type="text" id="email" class="detail" name="email" value=" <?php echo isset($_POST['email'])? $_POST['email'] : ''; ?>" /> <?php if(in_array('email', $validation)): ?><script type="text/javascript">alert("Please enter a valid Email Address"); history.back();</script><?php endif; ?> </div> <div class="fm-req"> <label for="fm-firstname">Number</label> <input type="text" id="telephone" class="detail" name="telephone" value="<?php echo isset($_POST['telephone'])? $_POST['telephone'] : ''; ?>" /> <?php if(in_array('telephone', $validation)): ?><script type="text/javascript">alert("Please enter telephone number"); history.back();</script><?php endif; ?> </div> <div class="fm-req"> <label for="fm-lastname">Message</label> <textarea cols="40" rows="5" id="comment" name="comment" class="mess"><?php echo isset($_POST['comment'])? $_POST['comment'] : ''; ?></textarea> <?php if(in_array('comment', $validation)): ?><script type="text/javascript">alert("Please enter your message"); history.back();</script><?php endif; ?> </div> <input class="submit_button" type="submit" value="Call us" /> </fieldset> </form> <?php else: ?> <p>Thank you for your Message!</p> <p>We will get back to you as soon as we can</p> <script type="text/javascript"> setTimeout ('ourRedirect()', 5000) function ourRedirect () { location.href='index.php' } </script> <?php endif; ?> Code: [Select] $sql="SELECT * FROM $tbl_name3 WHERE review_show='n'"; $result=mysql_query($sql); $num_results=mysql_num_rows($result); if($num_results > 1){ $message="You have ".$num_results." reviews unapproved."; mail('example@example.com','GHP Reviews', $message, 'From: example@example.com'); } $sql2="SELECT * FROM $tbl_name4 WHERE rma_issued='n'"; $result2=mysql_query($sql2); $num_results2=mysql_num_rows($result2); if($num_results2 > 1){ $message="You have ".$num_results2." RMA Numbers Requested."; mail('example@example.com','GHP RMA Number Requests', $message, 'From: example@example.com'); } The reviews email is being sent, however, the RMA email is not. EDIT: Nevermind, $num_results and $num_results2 should have been > 0 not > 1. Hi Guys I am creating a site which allows the registration of new users. I already have my user registration page up and running which is lnked to my database. I would now like to add a function which will send a 'welcome to...' email to the email address provided on the registration form provided by the new user. Could anybody please point me in the right direction i.e where to start? I am using dreamweaver and Cpanel. Thanksin advance Hi, I want to send an email to my registered users so that when they click on the URL given in the message hey should come back to my site as confirmetion of their registration. I am able to send the mail but the mail body is not coming as expected. Here's my code Code: [Select] <?php public function email($id){ //get users info $this->userInfo = $this->model->listUser($id); $this->sendEmail($this->userInfo); } public function sendEmail($data){ $to =$data['email']; $this->msg ="<img src=\"ideas.kpjit.com/public/images/header-img.jpg\" /> <h1>KPJ Idea</h1> <p>Make a difference</p> <p>This is a Confirmation Mail.Please confirm your registration by clicking here <a href=\"http://ideas.kpjit.com\register\confirm\ <?php echo $this->data['id'];?></p>\" "; $subject = "Registration confirmation"; $message = $this->msg; $from ="narjisfatima@yahoo.com"; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= 'From:narjisfatima@yahoo.com' . "\r\n"; if(mail($to,$subject,$headers)){ $this->render2("register/message"); exit; } } Also I am unable to insert my site banner in the mail. How can I do It. I am creating a forgotten password button, it works but it just doesn't send me an email containing the reset link.
Here's the code for the email part:
<?php require("../config.php"); if($_GET['code']) { $get_username = $_GET['username']; $get_code = $_GET['code']; $query = mysql_query("SELECT * FROM users WHERE username='$get_username'"); while($row = mysql_fetch_assoc($query)) { $db_code = $row['passreset']; $db_username = $row['username']; } if($get_username == $db_username && $get_code == $db_code) { echo " <form action='pass_reset_complete.php?code=$get_code' method='POST'> Enter a new password<br><input type='password' name='newpass'><br> Re-enter your password<br><input type='password' name='newpass1'><p> <input type='hidden' name='username' value='$db_username'> <input type='submit' value='Update Password!'> </form> "; } } if(!$_GET['code']) { echo " <form action='forgot_pass.php' method='POST'> Enter your username<br><input type='text' name='username'><p> Enter your email<br><input type='text' name='email'><p> <input type='submit' value='Submit' name='submit'> </form> "; if(isset($_POST['submit'])) { $username = $_POST['username']; $email = $_POST['email']; $query = mysql_query("SELECT * FROM users WHERE username='$username'"); $numrow = mysql_num_rows($query); if($numrow!=0) { while($row = mysql_fetch_assoc($query)) { $db_email = $row['email']; } if($email == $db_email) { $code = rand(10000,1000000); $to = $db_email; $subject = "Password Reset"; $body = " This is an automated email. Please DO NOT reply to this email. Click the link below or paste it into your browser http:/www.***REMOVED***.com/second/forgot_pass.php?code=$code&username=$username "; mysql_query("UPDATE users SET passreset='$code' WHERE username='$username'"); mail($to,$subject,$body); echo "Check Your Email"; } else { echo "Email is incorrect"; } } else { echo "That username doesnt exist"; } } } ?> |