PHP - Link To Open Email Client And Attach File?
Not sure if this relates more to PHP or Javascript/jQuery, but is there a way to attach a file to an email client (i.e Outlook), when user click on a link/button?
I have a link that generates a PDF and I want it so that, when someone click on a link, it will open up their email client with the PDF already attached, and subject already fill in. I know, you can use <a href="mailto:..." but that only opens up the mail client. I also need to attach a file with a subject fill in. Is this doable with PHP or Javascript? Similar TutorialsHi All, I don't really need help with the code, I just need to know the process... This will take place in a simple form. The user enters the payment information and checks off 'Send Receipt' option. From there, the payment data is stored in the DB. Then, I need to have a PDF generated of the receipt and finally email the tenant with confirmation and the PDF that was created. Once the data is inserted, I can use fPDF to merge the data to the PDF document I created. That part I don't understand is how to automatically save that file and attach it to an email. Ideas / suggestions? How to attach any file type to an email using php mail() It should attach any file that you select. What would be the Content-type: value? Thanks! Hi all I have a script that I have patched together and got to work in pieces. I'm up to the last part. I have the form working and emailing. It also will upload an image by itself and put it in a folder. Now i just need to tie those together and have the image put in the email as an attachment then deleted from server. I have it at a stage where it sends me the users details.. and it tries to send the photo but it comes through as junk txt. I think its the MIME encoding stuff that I have wrong.. not sure? Here's what I have so far. Code: [Select] $attachment = $path_of_uploaded_file; $fileatt = $attachment; // Path to the file $fileatt_type = "application/octet-stream"; // File Type $start= strrpos($attachment, '/') == -1 ? strrpos($attachment, '//') : strrpos($attachment, '/')+1; $fileatt_name = substr($attachment, $start, strlen($attachment)); // Filename that will be used for the file as the attachment $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 .= "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" . $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"; // create email headers $headers .= 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); Thanks Wolfsta This topic has been moved to PHP Freelancing. http://www.phpfreaks.com/forums/index.php?topic=318011.0 I have a page with links to images. Currently the images open in a blank browser window, and I think this is too plain. I don't want to create an HTML file for each image. I want to have an 'image display php file' - img_temp.php. Along with the reference to the image file, in the link, I want to also be able to send a <title> to the template file. I think the code below shows kinda' what I'm trying to do, and also shows that I don't quite have a grasp on how to do it. Any tips would be appreciated. Index Page (index.php) Code: [Select] <html> <head> <title>Gallery Links</title> </head> <body> <!-- This is the page with the links to the images --> <ul> <li><a href="img_temp.php?file=images/01.jpg<?php ?title = "This is image 1"?>">Image 01</a></li> </ul> </body> </html> Image Display Template (img_temp.php) Code: [Select] <html> <head> <title><?php echo $title ?></title> </head> <body> <!-- This is the page that displays the sent image and displays the appropriate doc title --> <?php //Output the image $file echo $file; ?> </body> </html> Hi, I have a form where a user selects a file to attach to the email. At the moment when you select a file it uploads from the user device. How do i change this so that a user can attach a file from a folder on the server. For example the folder name is uploadinvoice so when the user selects the browse button to attach a file it opens up the uploadinvoice folder on the server so the user can select the file from there ?
Thanks
coding i have at moment function ValidateEmail($email) { $pattern = '/^([0-9a-z]([-.\w]*[0-9a-z])*@(([0-9a-z])+([-\w]*[0-9a-z])*\.)+[a-z]{2,6})$/i'; return preg_match($pattern, $email); } if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['formid']) && $_POST['formid'] == 'form1') { $mailto = $_POST['youremail']; $mailfrom = isset($_POST['myemail']) ? $_POST['myemail'] : $mailto; $subject = 'Message'; $message = 'Message'; $success_url = './test.php'; $error_url = ''; $eol = "\n"; $error = ''; $internalfields = array ("submit", "reset", "send", "filesize", "formid", "captcha_code", "recaptcha_challenge_field", "recaptcha_response_field", "g-recaptcha-response"); $boundary = md5(uniqid(time())); $header = 'From: '.$mailfrom.$eol; $header .= 'Reply-To: '.$mailfrom.$eol; $header .= 'MIME-Version: 1.0'.$eol; $header .= 'Content-Type: multipart/mixed; boundary="'.$boundary.'"'.$eol; $header .= 'X-Mailer: PHP v'.phpversion().$eol; try { if (!ValidateEmail($mailfrom)) { $error .= "The specified email address (" . $mailfrom . ") is invalid!\n<br>"; throw new Exception($error); } $message .= $eol; foreach ($_POST as $key => $value) { if (!in_array(strtolower($key), $internalfields)) { if (!is_array($value)) { $message .= ucwords(str_replace("_", " ", $key)) . " : " . $value . $eol; } else { $message .= ucwords(str_replace("_", " ", $key)) . " : " . implode(",", $value) . $eol; } } } $body = 'This is a multi-part message in MIME format.'.$eol.$eol; $body .= '--'.$boundary.$eol; $body .= 'Content-Type: text/plain; charset=ISO-8859-1'.$eol; $body .= 'Content-Transfer-Encoding: 8bit'.$eol; $body .= $eol.stripslashes($message).$eol; if (!empty($_FILES)) { foreach ($_FILES as $key => $value) { if ($_FILES[$key]['error'] == 0) { $body .= '--'.$boundary.$eol; $body .= 'Content-Type: '.$_FILES[$key]['type'].'; name='.$_FILES[$key]['name'].$eol; $body .= 'Content-Transfer-Encoding: base64'.$eol; $body .= 'Content-Disposition: attachment; filename='.$_FILES[$key]['name'].$eol; $body .= $eol.chunk_split(base64_encode(file_get_contents($_FILES[$key]['tmp_name']))).$eol; } } } $body .= '--'.$boundary.'--'.$eol; if ($mailto != '') { mail($mailto, $subject, $body, $header); } header('Location: '.$success_url); } catch (Exception $e) { $errorcode = file_get_contents($error_url); $replace = "##error##"; $errorcode = str_replace($replace, $e->getMessage(), $errorcode); echo $errorcode; } exit;
} Hi All - I'm trying to see if the below is possible using PHP. is it possible for php to allow a user to check if a port is open/listening on a remote server/PC, from their local machine. I've seen scripts on the web that talk about opening cmd.exe - this won't work as not all of my users will be on windows. Also saw fsock.. but the remote server is not serving http page(s). Also saw telnet, but again, some of my users may not have that windows feature enabled. Desired workflow: 1. user enters the server hostname/IP and a port 2. my php webapp will emulate checking if that hostname and port is open from the local user's computer.
thanks! Hi This is for a simple email client. I am trying to create a delete button that deletes a message when in message view from the MySQL database. Bellow is what I have so far. Currently it sends an alert confirming the message has been deleted and goes back to the inbox view where, it is evident that nothing has been deleted. Even when I log out then back in, the message is still there. Code: [Select] // This is how I call the JavaScript function in the html page: <input type="button" value="Delete" onclick="deleteMessage();" /> // This is the relevant JavaScript: /* ~~~~~~~~~~~~~~~~~~~~~~~~~~ Functions used to Delete a message ~~~~~~~~~~~~~~~~~~~~~~~~~~ */ var requestDlt = false; // for the message to delete /* I created my own addition PHP script that, if correct, should delete a message when in message view */ function deleteMessage(mailNumber) { var url = "delete.php?mailID="+mailNumber; // assign to the url if (window.ActiveXObject) // if the users window matches this { // then requestDlt = new ActiveXObject("Microsoft.XMLHTTP"); // create a new ActiveXObject } else if (window.XMLHttpRequest) // else if the window matches this { // then requestDlt = new XMLHttpRequest(); // the global variable is an XMLHttpRequest } if (requestDlt!=null) // if the request exists { requestDlt.onreadystatechange=RequestFunctionDelete; // when ready envoke RequestFunctionMessage requestDlt.open("GET",url); // the request will now open the assigned url requestDlt.send(null); // send the request } } function RequestFunctionDelete() { if (requestDlt.readyState==4) // if all has been sent { // and if (requestDlt.status==200) // if it is all OK { /* if in message view, hide it, and show inbox */ if (document.getElementById("messageView").style.display!="none") { var response=requestDlt.responseText; // the variable response will hold the response text alert(response); // display the response to the user $("#messageView").fadeOut(1000, function() // hide message { $("#inboxBox").fadeIn(1000); // show inbox }); } else { // else /* Warn user they are unable to access button in this view */ alert("select a message you would like to delete"); } } } } // And lastly, here is the PHP Script that is called: <?php header('Content-Type: text/xml'); header("Cache-Control: no-cache, must-revalidate"); $dbhost = 'localhost'; $dbuser = 'cjc16'; $dbpass = 'cjc16'; $dbname = 'cjc16'; $dbtable = 'mail'; $id=$_GET["mailID"]; $con = mysql_connect($dbhost, $dbuser, $dbpass); if (!$con) { die('Could not connect: ' . mysql_error()); } $dbselect = mysql_select_db($dbname,$con); $sql="DELETE FROM $dbtable WHERE mailID='$id'"; $result = mysql_query($sql); if ($result) { echo "Deleted"; } else { echo 'Unable to delete'; } mysql_close($con); ?> Mod edit: [code] . . . [/code] tags added. I am wondering how to add a code to automatically send a copy as conformation to the sender. I need this code to send a exact copy to sender's email. I would appratite very much if someone can help. $nome = $_POST['nome']; $emaill = $_POST['email']; $to = "mail@mail.pt"; $boundary = "XYZ-".md5(date("dmYis"))."-ZYX"; $headers = "MIME-Version: 1.0" . PHP_EOL; $headers .= "Content-Type: multipart/mixed; "; $headers .= "boundary=" . $boundary . PHP_EOL; $headers .= "$boundary" . PHP_EOL; if(mail($to, $assunto, $mens, $headers)){ I tried add $headers .= "Cc: $emaill" . PHP_EOL; But don't work. Can you help me? Anyone know how I can print a file (specifically a PDF) that is stored on the server to the clients computer with a button? I don't want them to be able to view it, just print it. I've done some research and understand that there is no way to print directly without popping up the Windows Print dialog. And that is fine. I just want them to print this file, but not no where it is or be able to type in a URL to access it. Thanks Mike HI Gurus, I need to export (download) a csv file from the web server to my client. How can this be done in php ? How is the save as dialog invoked ? (I am assuming that file save permissions are allowed) I read that if you invoke the following script (eg form submit), it will work .. <? header("Content-type: text/plain"); header("Content-Disposition: attachment; filename=YOUR_FILE.csv"); ?> Any advice ? Steven M 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. Hi, I'm new here and new to php. My first attempt at a php project actually so I'm hoping to get some help. I want people to register at my site but I don't want them to put false emails on it. So I used the coding from this website http://www.phpeasystep.com/workshopview.php?id=24 to provide codings for forms and email confirmation links. The process worked up to when I click on the confirmation link (at testing) from the email and the link returns to a blank webpage. No data is transferred from "temp_members_db" table to "registered_members" table at all. I'll attach print screen of my tables. Hoping that someone can point out to me where I'm going wrong as I can't seem to get myself out of this one. I designed a web form that takes as input a file and that should upload that file on the server. The file is located on the client machine. The page containing the web form is handled by PHP script. I found out (reading 9483658954 forum topics so far) that there are 2 methods for getting a file uploaded. The first one is using FTP, and the second one using $_FILES variable. Unfortunately i have complains regarding both of the methods. Firstly, when attempting to upload the file using FTP it seems that rather the FTP server is calling "upload" a simple copy action (because the only successful thing i could do with FTP was to copy a file from location A to location B, both A and B being on the server) or I don't know to use FTP (which is probably the right answer). Then, when using $_FILES variable, I was forced to include ' enctype="multipart/form-data" ' in the form tag. After a long documentation I finally figured out that by including the enctype blah blah, the $_POST and $_FILES variables were NULL after the form was submitted.Still can't understand why! Are there any other methods for uploading a file from the client machine to the server? Can I get a competent script for this? here's my code that i've used to send an email. Code: [Select] $link = "<a href=\"http://www.example.com/" . $num . "\">" . $num . "</a>"; $query = "SELECT content FROM emails"; $result = mysql_query($query) or die(); $email_content = mysql_result($result, 0); $email = sprintf($email_content, $first, $name, $from, $link, $record, $rec, $inc, $max); $email_body = stripslashes(htmlentities($email, ENT_QUOTES, 'UTF-8')); // this is sent to another php script via post.... $subject = $_POST['subject']; $message = nl2br(html_entity_decode($_POST['email_body'])); $to = "me@whatever.com"; $charset='UTF-8'; $encoded_subject="=?$charset?B?" . base64_encode($subject) . "?=\n"; $headers="From: " . $userEmail . "\n" . "Content-Type: text/html; charset=$charset; format=flowed\n" . "MIME-Version: 1.0\n" . "Content-Transfer-Encoding: 8bit\n" . "X-Mailer: PHP\n"; mail($to,$encoded_subject,$message,$headers); in the db, emails.content is of the text type and contains several lines of text with %4$s which inserts the value of $link into the body. when the email arrives, there is a link and it appears fine, with the value of $num hyperlinked. however when you click on it it doesn't go anywhere. when copying the link location from the email it gives me x-msg://87/%22http://www.example.com/16 what is x-msg? how can i get this to work properly? If I want to open a new tab try target = blank in anchor tab I have a form with action e.g. register.php I also have a Google group API link - https://www.pakainfo.com/ in short... Is there any PHP function for open page in new tab; on page load... I have hardware setup to preform an action on camera when i enter a url into the address bar. Pretty much you will be able to feed tarantulas. I'd like to setup a button that my user can click that will active the url without being moved off of the current page. I can't figure out how to stop the browser from following the link to a blank page. It messes the whole thing up because the feeder only runs for a second and if you get sent to the blank page and have to navigate back the the live video feed page you could miss the feeding. Thanks for the help hello can i open file with name in another language rather than english. For example торта.jpg. How can i open that kind of file. I've tryed that <meta content="text/html" charset="utf-8" /> <?php $fh = fopen("торта.jpg", 'r'); fclose($fh); ?> but it's don't work. Help me pls! Alright I am so close but can not figure this out, thanks in advance for any help.
So what I am trying to do is take the input variables from a form and have them load a specific PDF .
<html> <body> <?php if( $_GET["startpoint"] || $_GET["endpoint"]) { $a = $_GET["startpoint"]; $b = $_GET["endpoint"]; echo "Your Startpoint is:". $_GET["startpoint"]. "<br />"; echo "Your Endpoint is: ". $_GET["endpoint"]. "<br />"; echo $a,$b,".pdf"; } ?> </body> </html>This is what I have and it works to display what the two points are what the final pdf file should be. The final echo generates the PDF name echo $a,$b,".pdf";How can I get it to load a file using this as a variable or the name it generates, thanks. Hello, I want to do, when someone click on button/link will open this: but not Save As, but Open. I know how to make simple form: <html> <body> <form action="edit.php" method="post" enctype="multipart/form-data"> <label for="file">File:</label> <input type="file" name="file" id="file" /> <br><br> <input type="submit" name="submit" value="Open"/> </form> </body> </html> But here You must click Browse, but I want to do like in photo: if You click on button, then at once will open form like photo. Many thanks, Tadas P.S. Sorry for my really bad English. |