Is this possible without having to first create a physical file on the server?
Initially I had to make a php page that would email each week information about new members of a site... That was fine I just used a cron job running the php page weekly... Now I've been asked to set up the email so it sends an Excel file of the data automatically... Does anyone know if this would be even possible? and how?
Regards,
Vinoth S
Yes, this is entirely possible. Libraries such as PHP Excel allow you to construct spreadsheets in memory without writing anything to disk. Libraries like Swiftmailer allow you to easily add attachments to e-mails from memory. Simply combine the two to do what you want.
Theoretically, one could create the email attachment by creating a carefully crafted email message. And then carefully constructing a document. This might mean breaking some of the email message composition rules if using the php email function.
Seems possible, but the most feasible implementations would be to use the well-suited tools to do it.
Do you know about OpenOffice? I think that can be scripted to run from a server context.
Related
I'm fairly new at using PhP, and I'm trying to write a script that will:
Connect to a mail server
Retrieve new emails
For each new email, extract as variables the sender's email address, the subject, and the message in plain text.
Mark the message as read once processed
The script would use these variables to interact with my database, and would be triggered by a CronJob every minute to check for new mails.
I've looked around a found a handful of library that apparently allow to interact with emails (IMAP, Zend Mail...). Before going any further, I have a few questions:
Do I need to install a library (I've never used one before) or do PhP have functions that would allow me to do what I want without having to install anything?
If PhP itself can do it, where can I find a tutorial helping me with that?
If I need a library, which one would recommand using and where can I find a tutorial to help me with it?
Thanks a lot in advance!
Arthur
For those with the same issue:
http://davidwalsh.name/gmail-php-imap
For French-speaking people (the code is understandable by non-French speakers):
http://nicolas-vieux.developpez.com/tutoriels/php/fonctions-imap/
I built support system (web) where my helpdesk can open new tickets/issues.
I want my clients to be able to send email with the issue text and file attache, to specific email address, and new ticket will be opened in my system.
For that I need to know how to scan the folder and how to add the email data to my DB.
what do I need to look for, in the internet, for that? what is the subject?
(I'm using PHP)
As the other's have commented, it's likely a larger task than you're ready to handle. But it doesn't hurt to try.
If I was tasked with the job, I'd take advantage of Gmail (for it's spam reducing features and large storage) to accept incoming email. From there, you simply need to setup a script that connects to your email account and processes the email for storage in your database.
Normally I recommend a solid library for making the job easier and cleaner, but I have a suspicion that you may not be familiar with OOP. If you at least know how to utilize classes, then check out Github:
https://github.com/search?l=PHP&q=imap&ref=searchresults&type=Repositories
Otherwise, if you're new and don't mind writing something "messy" then the following should at least point you in a good direction:
Connecting & retrieving emails for IMAP:
http://www.php.net/imap
http://www.php.net/manual/en/function.imap-open.php
Fetching/processing attachments:
(note that attachments are part of the email body)
http://www.php.net/manual/en/function.imap-fetchstructure.php
Storing attachments (in the filesystem):
http://www.php.net/manual/en/function.mkdir.php
http://www.php.net/manual/en/function.file-put-contents.php
There's plenty of Googling left for you to do. So go forth and make a lot of mistakes. Read the manual. Kick yourself for not having read it sooner, then go make more mistakes. Isn't that how most of us learn?
The first thing that comes to mind is to pop the most recent emails if you have pop3 set up or use imap functions. I did something similar to this using c# using openpop.net. So that could be a starting point.
You can use this method, using the cURL to fetch the emails from Gmail server through feed atom. XML response will return and we can convert it to HTML.
http://www.code4share.net/items/get-unread-email-in-gmail-by-php/XRGXVVh.html
I want to make it so that I can email a url and a php script or something at that url will take the contents I emailed such as message body and write them into a DB. I know how to write something into a DB but I dont know what to do in order to EMAIL to a url or person and have it pull out the message.
The reason I am thinking of emailing to a url if possible is because this saves me the massive blob of trouble of setting up IMAP and using all that mess. I know this can easily be done with php I just have no idea how.
You cannot send email to a URL, you must use a valid email address.
If you want to read your email from within php to import into a DB, you'll need to communicate to your IMAP/SMTP/POP3 server via a socket connection with the fsockopen() function.
I suggest you download any open source web based mail client such as RoundCube, Squirrel Mail, etc... and examine the source code.
There are quite a lot of options when it comes to receiving email. You'll still need to use an email address to send to but you can forward that email on via an HTTP POST using a couple of options such as cURL scripts or using a third party like CloudMailin.
I wrote a blog post about this in Rails (although the principles apply directly to PHP too without much modification. This is a dup of a couple of other questions but it was asked in a fairly different way hence the answer.
What is the best way to save a record of outgoing mail through the PHP mail function?
Basically, I want to archive the messages like the Sent folder in Thunderbird/Outlook.
The only 2 options I can think of is create a DB field, or save them at txt files on the server.
I was wondering if anybody had any suggestions, or methods I might be over looking
Either make a copy of the mail and store it yourself in your mailing script, or... and this one's quite handy: BCC a copy of the email to whatever account you want to be the archive of the sent messages. You can set up a mail folder rule to redirect those BCC'd copies into a specific folder if need be.
I suggest saving them in database since it makes searching them a lot easier than plain text files
If there is a massive amount of mail look into MongoDB. It is a NoSQL DB and many sites use it for archival purposes.
I would save them in a database. When the emailer runs to send out messages, a copy is added to the database. You can also keep track when the email was sent and all that fun information. It will make searching the database easier later. Text files would be a pain, imo.
I'm required to create a newsletter php application that would send template emails to all subscribed to the system users.
We're currently using PostgreSQL so PhpList will not work for us if it's not capable to work with PostgreSQL.
What's the appropriate way of handling this task ? Also keep in mind that there will be big amounts of subscribers.
Edit: I'm opened to java applications that could do the trick..
Thanks in advance.
Get Mailman:
http://www.gnu.org/software/mailman/index.html
Then send your newsletter to mailman (that's just one adress) and allow mailman to distribute the Newsletter to thousands of recipients (that you configure in Mailman). Of course there is other software besides Mailman, that can do just that...
To make a custom newsletter daemon you can use System::Daemon.
Try using this example for daemons: http://kevin.vanzonneveld.net/techblog/article/create_daemons_in_php/
Beware:
If you make daemons that will run infinitive you should be aware that php caches things in the ram. So if you're not careful you'll end up with no ram :)
This tutorial is concentrating in sending out emails as such there's no login area covered, but it's recommended you should have your script to send emails stored somewhere secure so only people who should be able to access it can do.
Lets start with the form, all we need is a field for the subject and a field for the message, you can put HTML into the message as we will filter it out for the text email later