How to send email with attachment using PHP?

I’d suggest to use a library for sending eMails as it will handle all the header related stuff. Have a look at Zend_Mail. Sending attachments is as easy as $mail = new Zend_Mail(); $at = $mail->createAttachment($myImage); $at->type=”image/gif”; $at->disposition = Zend_Mime::DISPOSITION_INLINE; $at->encoding = Zend_Mime::ENCODING_8BIT; $at->filename=”test.gif”; $mail->send();

GMAIL API for sending Email with attachment

// Get the canvas from the DOM and turn it into base64-encoded png data. var canvas = document.getElementById(“canvas”); var dataUrl = canvas.toDataURL(); // The relevant data is after ‘base64,’. var pngData = dataUrl.split(‘base64,’)[1]; // Put the data in a regular multipart message with some text. var mail = [ ‘Content-Type: multipart/mixed; boundary=”foo_bar_baz”\r\n’, ‘MIME-Version: 1.0\r\n’, ‘From: … Read more

Sending mail attachment using Java

Working code, I have used Java Mail 1.4.7 jar import java.util.Properties; import javax.activation.*; import javax.mail.*; public class MailProjectClass { public static void main(String[] args) { final String username = “[email protected]”; final String password = “your.password”; Properties props = new Properties(); props.put(“mail.smtp.auth”, true); props.put(“mail.smtp.starttls.enable”, true); props.put(“mail.smtp.host”, “smtp.gmail.com”); props.put(“mail.smtp.port”, “587”); Session session = Session.getInstance(props, new javax.mail.Authenticator() { … Read more

How to send an email with a file attachment in Android

Use the below code to send a file within a email. String filename=”contacts_sid.vcf”; File filelocation = new File(Environment.getExternalStorageDirectory().getAbsolutePath(), filename); Uri path = Uri.fromFile(filelocation); Intent emailIntent = new Intent(Intent.ACTION_SEND); // set the type to ’email’ emailIntent .setType(“vnd.android.cursor.dir/email”); String to[] = {“[email protected]”}; emailIntent .putExtra(Intent.EXTRA_EMAIL, to); // the attachment emailIntent .putExtra(Intent.EXTRA_STREAM, path); // the mail subject emailIntent .putExtra(Intent.EXTRA_SUBJECT, … Read more

How to attach two or multiple files and send mail in PHP [duplicate]

<form action=”#” method=”POST” enctype=”multipart/form-data” > <input type=”file” name=”csv_file[]” /> <br/> <input type=”file” name=”csv_file[]” /> <br/> <input type=”file” name=”csv_file[]” /> <br/> <input type=”submit” name=”upload” value=”Upload” /> <br/> </form> <?php if($_POST) { for($i=0; $i < count($_FILES[‘csv_file’][‘name’]); $i++){ $ftype[] = $_FILES[‘csv_file’][‘type’][$i]; $fname[] = $_FILES[‘csv_file’][‘name’][$i]; } // array with filenames to be sent as attachment $files = $fname; // … Read more

Send File Attachment from Form Using phpMailer and PHP

Try: if (isset($_FILES[‘uploaded_file’]) && $_FILES[‘uploaded_file’][‘error’] == UPLOAD_ERR_OK) { $mail->AddAttachment($_FILES[‘uploaded_file’][‘tmp_name’], $_FILES[‘uploaded_file’][‘name’]); } Basic example can also be found here. The function definition for AddAttachment is: public function AddAttachment($path, $name=””, $encoding = ‘base64’, $type=”application/octet-stream”)