I know that SwiftMailer is used for sending emails, but I'm trying to parse an email that has come into my PHP script. We already use SwiftMailer in our Symfony site, so I'd like to use it, if it can do what we want.
Scenario:
The email is piped into my PHP script by postfix. I then grab this from StdIn and want to load it into SwiftMailer so I can get easy access to the components - i.e. attachments / headers, to / from etc..
I've searched around on this and tinkered with the SwiftMailer code and can't find any examples or even any indication of direction to look in.
Any help would be gratefully received.
Related
I need to do some test for email sending in wordpress. I've noticed that I can only use mailtodisk utility but it will only work with the build PHP mail() function and not with wp_mail(). Since I have a pdf file to attach, is there any solution I can use to achive my scope?
At the moment I have the needing to send an email to a customer that will input his address in a form and will have a specific subject and message body, and another to some stores with different email and different message and subject, the only common thing is the attached file.
Any suggestion? I've read that I can use php mailer that is built in in wordpress, but how I make it works correctly?
Once or twice a year i find myself in the position of having to develop complex emails.
They often include Plaintext and Html versions, along with attachments and other headers.
Previewing the development using standard send/receive is painfully slow and tedious.
What i'm looking for is a local testing platform that processes the mail function and provides a mail client style preview with access to alternate views, headers, etc. Or possibly a real mail client that can take mail directly.
I've searched and searched but no luck so far, hopefully someone can point me in the right direction.
Thanks in advance. TT
I'm not sure if this is what you want but you can use your localhost mail and access it via thunderbird for example
How do I read local email in thunderbird? - Ask Ubuntu
Via this way you don't have to wait endless for mail to be delivered as it's local. And you can see your send mail in a actual mail client
I don't know any software but I had some good experience with the following online service: http://litmus.com/ It's somewhat like browserstack. (live crossbrowser testing tool)
I use Papercut, which listens to a SMTP port, catchs all e-mails and shows headers, source, text and html view. It's very useful!
I have now solved this.
In the php.ini file there is an option to set an export path for the mail function called sendmail_path.
I set this to tee mail.eml > /dev/null and it now saves the sent mail to the same directory as where the function is called and i simply open it with my mail client.
sendmail_path = tee mail.eml > /dev/null
2 notes on this.
this is a solution for unix platforms only.
the file extension has to be set to suit your chosen mail client
For a task like this I use fakemail for receiving the mails into a maildir and mutt for reading the mails. Mutt can also be configured for reading HTML mails.
If you just want to log the emails without reading them, you could use the "logmail" approach described in this article by Chris Shiflett:
Edit: The lastcraft.com host seems to be down at the moment, my Google search for "fakemail" revealed this Python project that might be helpful: https://github.com/isotoma/FakeEmail
If you're just looking to preview your HTML emails (and alternatively, if you need help designing them) you can sign up for a free MailChimp account. It's actually an email send service, but they also have an interface for a drag-and-drop email builder.
For your situation, you could use the "code your own" tool, drop in your HTML, CSS, plain text, etc. and then preview the email in all sorts of email clients, test at different screen resolutions, etc.
(*I am not affiliated with MailChimp)
You can also try https://github.com/ycecube/phpmaildebug.
It uses the php's sendmail output to capture the mails.
I am using this PHP form builder class but I think I'm missing the very basic which is how to send the email. I know enough php to download and modify the code but not quite sure how to implement:
mail(to,subject,message,headers,parameters)
Does anyone know how to get this working and send the email to myself when the form is submitted?
Take a look at the PHP documentation, or better use some abstracted class like swiftmailer. Swiftmailer will save you some hassle down the line, as it sets the headers correctly and is independant from the mail subsystem.
Here is a basic example how to include swiftmailer
You don't have to implement the mail function, it should already be there and it has been there by default since PHP 4.
If you're not finding a mail function (or if it is not working), then chances are that you are not running on a machine where PHP has access to the sendmail command. You can read about the requirements of the mail function here. If this is the case (and you have to be able to test the emails), then you will need to get a mail server. If you're on Windows, I know that XAMPP comes with one, but I normally do that sort of development with a Linux box.
I have a feature in my app that handles and parses incoming emails.
The mails come in through the usual method with exim as a .forward file:
| /path/to/php /path/to/mail/handler.php
This sends RFC822 formatted text to my handler, which uses a parser to break it down and hand over to the rest of my app.
New feature needs to be added to forward any mails to foo#mysystem.com along to bar#othersystem.com
I'm trying to figure out a way to do this the most simple way. The long way is to take the parsed message, modify the To: address and send on as a new mail.
So my question is: What's the simple way to "forward" an RFC822 formatted message? Is there a way of telling exim to forward the mail instead?
You should have Exim do this, not PHP. Mail servers are all about forwarding email. There should be a way to add multiple addresses in your .forward file. If you can't figure out how, https://serverfault.com/ is the place to ask.
i am searching for a way to read mail messages from a PHP application, including access to attachments etc. imap functions are not acceptable as a solution, as this application will handle mails with heavy attachments.
i have full access to the server's mail folder from php via filesystem. any thoughts?
I think you could use a combo of the Pear packages Mail_Mbox and Mail_mimeDecode. Use Mail_Mbox to read new mail from the inbox, one message at a time, and use Mail_mimeDecode to extract the attachements. All this will be done w/o IMAP. You can then save the read messages to a different mbox to keep the inbox clean.
Pear - Mail_Mbox
Pear - Mail_MimeDecode
I had a question like this a while back. See if any of the answers help you:
How to get email and their attachments from PHP
postfix + maildrop was the solution I ended up taking, It routes the emails through to a PHP script when it arrives and in my case, the PHP does something with the attachment. But I only needed to read each email once. If you need to be able to browse all the emails, you either need to store the results of maildrop or find another solution.
If you need to full access to all emails, POP and IMAP are popular choices because they do work. I'm not sure why you're against them.