I want to download to get the following information from my emails
sender
sender_email_address
subject
Message
attachments = array(
all attachments
)
any library? suggestions? links?
I have used https://github.com/EllisLab/CodeIgniter/wiki/IMAP and it worked just fine.
Good luck
Here is the library that can be used..
http://garrettstjohn.com/entry/reading-emails-with-php/
plus accessing the library, extracting email and its attachments
http://garrettstjohn.com/entry/extracting-attachments-from-emails-with-php/
Something that was missing in this extraction, was a function to process image, so I had to do it...
function _process_img($attach, $ext){
$directory = "uploads";
$path=realpath(APPPATH."../".$directory);
$file_name="any_name_you_want_to_give".".".$ext;
$file=$directory.$file_name;
if(file_put_contents($path."/".$file_name, $attach)) return $file;
}
Hope it will help someone else too...
Related
using codeigniter 1.5.2 framework,i try to upload file send as an attachment in mail but when mail send it shows .dat file and not relevant to file I send.
$attachfilepath = $_FILES['userfile']['tmp_name'];
$attachfilename = $_FILES['userfile']['name'];
$CI->load->library('email');
$CI->email->from($adminemail, 'Client Name');
$CI->email->to($to);
$CI->email->subject($subject);
$CI->email->message($message);
$CI->email->attach($attachfilepath,$attachfilename);
$CI->email->send();
P.S- i heard this versions attachment function is not stable but attachment function is working when give local file
#bhugy I think this is some bus of the codeigniter version.
we cant use temp file save path in this version of codeigniter.but we can use this logic when we use pure php. (may be new version of codeigniter)
I don't think you can attach files in that way.
I can't specifically find the old 1.5.2 code so I cannot 100% confirm this
attach($filename, $disposition = 'attachment')
^^ this is the method signature from the Email library 2.x
attach($attachfilepath, $attachfilename);
^^ You are not doing it correctly.
I think you need to do.
$attachedFileLocation = $attachfilepath . $attachfilename
$CI->email->attach($attachedFileLocation);
^^ you may need to add a forward slash between the 2 so that it creates a full path but that is something you will have to debug.
Hopefully this sorts your issue.
P.S. I would also suggest upgrading to CI 2 because there are not that many breaking changes between the 2 version but many minor issues were addressed.
I'm having really a hard time with TCPDF, in what I am seeing from my searching here in Stack Overflow, I can't find any help in understanding on how to use TCPDF. I can't figure out on how to include tcpdf in my website unlike FPDF, I'll just have to copy paste required folders and files inside the folder of the website then place a require(fpdf.php); in the pages. How do I do that in TCPDF?
I can't even figure out how to connect to my database unlike FPDF.
I want to know the basics in understanding TCPDF.
Can someone guide me in understanding TCPDF?
I have used this DOMPDF tutorial to convert my HTML file into PDF. You can send this PDF file to user mail also. It is very easy to understand. Try this and please let me know whether it help you or not. You can see demo here
EDIT :- If you don't want to send a mail then just remove the following code from form.php
// Load the SwiftMailer files
require_once($dir.'/swift/swift_required.php');
$mailer = new Swift_Mailer(new Swift_MailTransport()); // Create new instance of SwiftMailer
$message = Swift_Message::newInstance()
->setSubject('How To Create and Send An HTML Email w/ a PDF Attachment') // Message subject
->setTo(array($post->email => $post->name)) // Array of people to send to
->setFrom(array('no-reply#net.tutsplus.com' => 'Nettuts+')) // From:
->setBody($html_message, 'text/html') // Attach that HTML message from earlier
->attach(Swift_Attachment::newInstance($pdf_content, 'nettuts.pdf', 'application/pdf')); // Attach the generated PDF from earlier
// Send the email, and show user message
if ($mailer->send($message))
$success = true;
else
$error = true;
As always here is the place where I have learned a lot. And I have now a new things to learn:
I have a html form:
<tr><td width="16%">File attachment</td><td width="2%">:</td><td><input type="file" name="fileatt" /></td></tr>
and a mail.php:
$attachfile=$_POST["fileatt"];
and a correct swiftmailer code to send emails out;
I have googled and I found many examples how to send attachment with a file stored on the website but I would like to do it on the fly. So when you submit the button it would send it to peoples out rather than uploading the file.
// Create the Transport
$transport = Swift_SmtpTransport::newInstance('mail.server.co.uk', 25)
->setUsername('user')
->setPassword('pass')
;
// Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);
// Create a message
$message = Swift_Message::newInstance($subject)
->setFrom(array('emai#emai.com' => 'name'))
->setBody($html, 'text/html')
;
// Add alternative parts with addPart()
$message->addPart(strip_tags($html), 'text/plain');
// Send the message
$result = $mailer->send($message);
could anyone help me how to do the on the fly file uploading, please? Thanks in advance!!!
There's a simple way to do this, here you go:
$message->attach(
Swift_Attachment::fromPath('/path/to/image.jpg')->setFilename('myfilename.jpg')
);
That's one way SwiftMail can do this, now just the /tmp file, and turn the above into the following:
Assuming: fileatt is the variable for the $_FILE, ['tmp_name'] actually is the tmp file that PHP creates from the form upload.
$message->attach(
Swift_Attachment::fromPath($_FILES['fileatt']['tmp_name'])->setFilename($_FILES['fileatt']['name'])
);
More information on SwiftMail Attachments can be found on this docs page
More information on $_FILES can be found here on w3schools, despite I don't like w3schools, this page is solid.
Another way to do this, using only a single variable for path and filename is:
$message->attach(Swift_Attachment::fromPath('full-path-with-attachment-name'));
Single Attachment
My answer is similar to that of André Catita. However, in Laravel 6 you can use $request instead of $_FILES. Let me simplify the code above:
$path = $request->file('import')->getPathName();
$fileName = $request->file('import')->getClientOriginalName();
$message->attach(
Swift_Attachment::fromPath($path)->setFilename($fileName)
);
Here I assume that the name of your file tag is import. For eg: <input type="file" name="import" />
Multiple Attachments
Now, lets say instead of single attachment you need multiple attachments. Then the code needs to be changed.
First your html code will become: <input type="file" name="import[]" multiple />
And for backend or laravel; code will be:
$files = $request->file('import');
foreach($files as $file){
$path = $file->getPathName();
$fileName = $file->getClientOriginalName();
$message->attach(
Swift_Attachment::fromPath($path)->setFilename($fileName)
);
}
This question already has answers here:
How to embed images in email
(6 answers)
Closed 9 years ago.
Duplicates:
How to embed images in email
How to embed images in html email
Embed images for use in email message using PHP?
I am sending HTML emails using php. I want to use embedded images in the HTML. Is it possible? I have tried lot of different methods, but none are working. Is anyone able to help me please?
Thanks
You need to provide the whole url where your image resides
example:
<img src='http://www.mydomain.com/imagefolder/image.jpg' alt='my-image' width='' height=''>
This isn't really trivial, but with a couple of tries doable.
First of all, learn how to build a multipart email, that has the correct images attached to it. If you can't attach the images, they obviously won't be in the email. Make sure to set the type to multipart/related.
Secondly, find out how to set the cid references, in particular the Content-ID header of the attachment.
Third, glue it all together.
At each step, do the following:
look at the result
send the email to yourself, and compare it to what you received
compare it to a working example email
I find the best way to send images via email is to encode them with base64.
There are loads of links and tutorials on this but here is this code for Codeigniter should suffice:
/* Load email library and file helper */
$this->load->library('email');
$this->load->helper('file');
$this->email->from('whoever#example.com', 'Who Ever'); // Who the email is from
$this->email->to('youremailhere#example.com'); // Who the email is to
$image = "path/to/image"; // image path
$fileExt = get_mime_by_extension($image); // <- what the file helper is used for (to get the mime type)
$this->email->message('<img src="data:'.$fileExt.';base64,'.base64_encode(file_get_contents($image)).'" alt="Test Image" />'); // Get the content of the file, and base64 encode it
if( ! $this->email->send()) {
// Error message here
} else {
// Message sent
}
Here is a way to get a string variable without having to worry about the coding.
If you have Mozilla Thunderbird, you can use it to fetch the html image code for you.
I wrote a little tutorial here, complete with a screenshot (it's for powershell, but that doesn't matter for this):
powershell email with html picture showing red x
And again:
How to embed images in email
I was just wondering if I could have a variable to hold an image, I'm using phpmailer to send email and I need an image to be attached to it,
so I was wondering if I could put the image in a variable and use
$mailer->AddAttachment($image);
to send the email with attachment.
thanks for your help.
With PhpMailer adding an attachment is done the way you wrote it in the question
$mailer->AddAttachment('/home/mywebsite/file.jpg', 'file.jpg');
If you want to use a variable you can change the string by a variable without problem.
$imagePath = '/home/mywebsite/file.jpg';
imageName = 'file.jpg'
$mailer->AddAttachment($imagePath, $imageName);
I guess $image should contain local path to the image file.
If you look at phpMailer source, at line 1218:
http://phpmailer.svn.sourceforge.net/viewvc/phpmailer/phpmailer/trunk/class.phpmailer.php?revision=444&view=markup
you'll see that it verifies at first that what you have given is path to existing file. There is no other option.
Unless I'm missing something, that's exactly how it's supposed to be used.
According to this document, you'd do something like this:
$myImg = '/some/path/to/image.jpg';
$mailer->AddAttachment($myImg);
Is that not what you're trying?
Why cant you do this this way? Sending email attachments in PHP Using phpmailer class !