I cant track down the event in the framework, which is logging mails sent (via mailgun api). It is dumping raw attachment data (in my case, pdf splurge) into the log - and I want to stop this!
I have found what looks like the the event and it being fired
vendor\laravel\framework\src\Illuminate\Mail\Events\MessageSending.php
But cant see where it actually does anything!
Is this possible to either disable logs? Or stop it logging attachment data
Thanks
Related
The goal
I am trying to create a PHP script which emails a rather large (6MB) PDF file to users on a website that request it. A user enters their email address into a form, submits the form, and the file is sent to them via a PHP Mailer instance. The user is displayed a success page on submitting of the form.
The problem
After the data is submitted via the POST method, there is a long pause and the server eventually returns a 404. However, the email is received perfectly fine with the PDF attachment after a few minutes.
Troubleshooting / attempted solutions
I attribute the problem to PHP Mailer simply taking too long a time to send the email because of the large attachment. The server times out and resorts to returning a 404. In the mean time, the script eventually finishes processing and the email is thereafter received.
If I remove the attachment and just send a blank email, the script loads very quickly and shows the success/confirmation page.
I have considered creating a redirect, but everywhere that I have found explanations on how to achieve a redirect in PHP, it is said that you should kill the original script (which I do not want to do).
The question
How do I allow the email script to take its time to run, while immediately displaying a success message to the user so they are not left confused?
This is a task for a message queue. Store all information needed to send the mail in a queue and have a background task taking this information and sending your mails. If the insertion to the message queue succeeded, display the success message to the user.
If you do not have access to background scripts (e.g. shared hosting), you can still have a direct response. Just use ignore_user_abort(true) and send a correct Content-Length header. Browsers will trust that header and show the response, while your script can continue running and send the mail.
Another solution: Do a quick trick instead of attaching a big file in the email instantly. Give them the download link of the PDF File. Thus the content becomes too short. But no attachment.
You can effort to create unique URL to download the same PDF file by different users.
Otherwise, email queuing is good, as discussed.
Instead of emailing the file immediately, store the request in a database with all the details you need in order to send it. Then you can use a cronjob/scheduled task to regularly (every minute if you like) check the database for any outstanding requests and send the emails in the background.
As no codes were provided, you can use AJAX to call your script and show a success message wherever you want. The script will be called, the user will get the message and as soon the script finish, the user will receive the email.
Of course, the success message shouldn't be implemented in the AJAX handlers, otherwise the message will be delayed as well.
This is a good use case for an asynchronous job queue such as Gearman or Beanstalk.
You have to run an external worker process that will wait for tasks from the job server.
On the web server side, just create the task, send it to the job server to dispatch it to the worker process, and exit the PHP script.
The worker process will then proceed to send the mails while the web server can continue serving HTTP requests.
I've read an article from the Symfony2 Cookbook, called "How to work with emails during development", specifically "Viewing from the web debug toolbar". It said that if an email is send and request than redirected, you can still view sent email with 'intercept_redirect' option. However, there is no information regarding how to view an email that was sent with AJAX request...
I believe that such function was implemented in 2.6, according to this article. But most of my project using 2.3, and currently I'm using dirty things like dumping content in response to view it on Network tab in browser toolbar, but that's quite bad for testing purposes.
I've read solutions like this one, but there is still no info about emails.
Maybe anyone had a similar issue? Thanks in advance.
The only thing you actually need is having access to debug tokens for your AJAX requests, so you could then open up the profiler and look at the mailer stats. The easiest way to do this would be:
$(document).ajaxComplete(function(event, XMLHttpRequest, ajaxOption) {
if (XMLHttpRequest.getResponseHeader('x-debug-token-link')) {
// This is the link to debug panel
console.log(XMLHttpRequest.getResponseHeader('x-debug-token-link'));
}
});
This would log all the profiler links to the console. So, after an XMLHttpRequest has completed you could open them up and see whether your emails were sent.
I'm programming a calendar website. The reminder message should be sent using kik.
Therefore I need to send a message even if the page is not actually called.
Is there a possibility to do this, for example using a timer that is set when the date/event is
put into the calendar from the user
thanks for your help
This is not possible. The Kik API is structured in a way that messages can only be sent with the user's explicit permission.
Push notifications are an alternative for your kind of use-case. Check out the documentation here: http://dev.kik.com/docs/#push
I was wondering if during the time of my User Registration for my site, I can create an SMTP account something like : username#mydomain.com for that user using PHP?
And also, some method of receiving/fetching the mails using PHP into my DB so that it can act as a mail client as well?
The closest answer I could find was using something like "procmail" or some service like : "http://www.cloudmailin.com/"
However, is there no other method to do it?
For example, when we send a mail at someuser#facebook.com it goes directly to his message box. How is this happening?
Another way to do this is to setup your mail server to accept mail to *#yourdomain.com, and forward all incoming messages to your PHP script which will parse each incoming message, update your DB, etc. For more info on how to set this up, see: http://harrybailey.com/2009/02/send-or-pipe-an-email-to-a-php-script/
I have a page which handles form input. It does a few things, sends a few emails, and redirects the client to another page. Things work well.
The issue I that sending email is slow, and if I have to send a couple emails, the response time is unacceptable. I would like to redirect the client to the result page, and then send the emails. Unfortunately, the redirect() call in CodeIgniter ends execution.
Is there a way to do a 302 redirect and allow the execution of the script to continue?
It is important that the 302 redirect headers get flushed out. It would be OK, but is not required, that the connection be closed. What is important that the user gets redirected before the emails get sent, in order to not have to wait for the email sending to finish.
I think using a message queue would be more appropriate than having a possible zombie process sitting there. Essentially when this action is taken dump a job into a job queue with the body of the e-mail, who it's going to, the subject etc. Then have a cron job set up to read this queue every two minutes, say, and send out the e-mail.
You can also look into using something like the Simple Queue Service from Amazon (http://aws.amazon.com/sqs/faqs/#What_can_I_do_with_Amazon_SQS) along with the Simple E-Mail Service to create a scaleable solution.