I have a laravel app with a form that when it is submitted will send a mail.
The mail configuration is working properly since the mail is received.
But since the process was quite slow i decided to use Queue.
I have set up Iron mq account and set it up on Laravel4.
So instead of Mail::send i switch to Mail::queue. Here is the code:
return \Mail::queue($this->view, $this->data, function($message) use($self)
{
$message->to($self->email, $self->to)->subject($self->subject);
});
And in the routes there is simply:
Route::post('booking', 'HomeController#booking');
Route::post('rezervesana', 'HomeController#booking'); // This is for the latvian version
When i submit the form, the queue is received in Iron mq dashboard and apparently fired.
But no mail is received..
If instead i do something like this:
Route::post('booking', function()
{
return Queue::marshal();
});
Then magically it will work in the latvian version (rezervesana) but of course than the english version page does not even open anymore..
So I am quite confused.
The question is: How can I send properly a mail using Mail::queue and how to deal with it in the routes?
I think that the code regarding the Mail::queue is correct, what is wrong can be in routes.
So the real question can be: How I have to set up the routes to make queue working properly?
Which is the proper place for Queue::marshal?
Thank you guys!
Sorry if it is confused.
Hope you can clarify it to me!
I've used SQS before but not Iron, maybe you should use this?
Route::post('booking', array('before'=>'csrf', 'uses'=>'HomeController#booking'));
Related
Since yesterday I have had problems sending emails with Lumen. I think I have followed all the steps in the documentation correctly, but unfortunately I cannot send anything. Moreover, no error is displayed (I have activated APP_DEBUG=true), and I am sure that the credentials of the smtp server are correct. I also did composer require illuminate/mail.
Here are my modifications in bootstrap/app.php (I have $app->withFacades(); uncommented).
Here is my build function content: return $this->view('emails.mailTemplate', ['message' => $this->message]);.
And the line of code that ask to send mail: Mail::to("wewanthalflifethree#gmail.com")->send(new sendMail($destEmail, $subject, $message));.
Did I do something wrong? :/
Thx in advance for help!
EDIT: I just noticed something, the code stop working when I send the mail. If I add an echo after Mail::send, it will be appear on the page.
I have a problem with the Exceptions handler. By following this answer (which consists in adding a dd in the render function of Handler.php), I am now able to see what's going wrong.
So, here is the reason why my mail didn't send and why my page turned blank: Object of class Illuminate\Mail\Message could not be converted to string (View: /home/serveur-web/api.sl-projects.com/resources/views/emails/mailTemplate.blade.php).
The problem came from the fact that I was using the variable name $message, and this causes problems because it seems to be used in the class that handles the mails. My problem was therefore solved by renaming this variable $mailContent.
I hope this will help other people. :D
I've been searching a lot, but can't really find what i exactly need.
Im running a shop-online using XAMPP, and what i want is send emails to the customers with their order but using a specific function.
What this fuction does, is to hide some characters (for security purpose) on the email sent to customers. So i've made the function (looking on internet), but i want to test it now.
This is my function (if it's wrong, i'd really appreciate some help):
<?php
function xtc_hide_iban ($iban) {
$length = strlen($iban);
$lchars = substr($iban,0 ,5);
$rchars = substr($iban, -5);
$iban_hidden = $lchars.str_repeat('*',$length-10).$rchars;
return $iban_hidden;
}
?>
I think it's pretty obvious what i try to do, but i will still explain it:
Get the $iban from customers, and show only the first and last 5
characters when the email is sent e.G
Your IBAN is 'DE123************56789'
So, for now i can send emails from Mercury mail server to 'root#localhost',account i made on thunderbird, (it's the only account that worked for me, because any other with the same server, like 'anyname#localhost' didn't work or couldn't be created, and those who were create with imap before couldn't access to the inbox "could not connected to server, connection refuse", anyway this works with POP3)
Following what i looked before, is that somehow and somewhere i can put a *.php on Mercury folder so i will get a template of how to send the mails (headers, subject,body,etc).
My main question is how and where to do that? make a test php file to make sure my code is doing what i want to do
Thanks in advance
I've got an odd problem that I can't put my finger on.
In my controller, I'm sending an email using swiftmailer, setting a flash message using the session flashbag, and redirecting to another page.
public function testAction() {
$this->get('session')->getFlashBag()->add('info', 'test flash message');
$message = new \Swift_Message('test', 'test');
$message->setTo('email#example.com');
$message->setFrom('email#example.com');
$this->get('mailer')->send($message);
return $this->redirect($this->generateUrl('home_page'));
}
After the redirect, I expect to see the flash message, but it seems that something happens when the mail is sent that makes the flash message delayed by one request. That is, I don't see the flash message when I get to 'home_page', but I do if I reload the page after the redirect.
If I comment out the send() call or even set disable_delivery: true in the swiftmail configuration, the flash message works as expected.
I thought I might have found a bug, but when I created a new project (symfony/framework-standard-edition 2.4.1) and tried this, it works even when I send mail. I've checked to make sure I'm using the same releases for swiftmailer, symfony, etc. So, I'm sure it's something with my project, but I am out of ideas of where to go from here.
I'm using PHP 5.5.7, Symfony 2.4.1.
Thanks for your time
A quick fix is to disable spooling for SwiftMailer. I am still uncertain whether this is the actual solution, but it seems to work.
By disabling spooling, the mailer will block execution while sending the mail.
I commented out the line that enables spooling:
#spool: { type: memory }
By default, the mailer will not use spooling but send the mail right away: http://symfony.com/doc/master/cookbook/email/spool.html
I believe there's a bug when using PdoSessionHandler for storing sessions - if you use native session storage the problem goes away and the flash message works as expected with SwiftMailer.
The flash messages (app.session.flashbag) rely on sessions to store the data between page loads.
I am using fake mail for windows, For long time i got a problem with the FIRST mail i am sending, What i mean is that for example i am using php so i will use this line:
mail("example#gmail.com", "hey", "bye");
If i will load the page with this mail function for the first time the mail function will return false, But the second time and third and so on it will work, But, After some time i can not determine how long exactly, I can say the gmail mail server "going to sleep", And again when i am sending a mail for the first time its like, Ohh you need a mail to send give me a second(the first mail return false), After the mail server got the second it wanted it will send the mail(return true), I did follow this tut, The error appear at the error.log is: Connection Closed Gracefully., Now as i see it there is a problem on my gmail account(some setting i should change), Anyway If anyone got any idea i will be very thankful, Thank you all and have a nice day.
After researching this bug, it seems to be a bug of the mail() function. One alternative is to download the phpMailer library, and implement your mail function there. The other alternative, since you say that the second time it always works, is:
if (!mail("example#gmail.com", "hey", "bye"))
mail("example#gmail.com", "hey", "bye");
In other words, if it fails once then you try again. You might insert a 300-milisecond pause there in case Google needs some time to come back from sleep.
I'm testing out the Pusher library for handling websockets with a rather simple app using PHP and Javscript (jQuery) you can find it here: http://jsfiddle.net/JyVvr/1/
Tha backend ajax.php file contains this:
require 'lib/Pusher.php';
$message = $_POST['msg'];
$pusher = PusherInstance::get_pusher(); // My API key, secret, etc is directly set in the Pusher.php file
$pusher->trigger(
'test_channel',
'new_comment',
array('message' => $message)
);
echo json_encode(array('message' => $message));
Basically the app just takes a message and appends it to the ul element on form submit, the appending part works just fine but the new_comment event isn't triggering so the app isn't working as intended, I used an alert just to test if it showed but it just does nothing plus it doesn't throw any errors or anything. Can anyone tell me what am I doing wrong?
Thanks in advance!
If the events aren't reaching Pusher, make sure the Pusher server time and your server time match or are within 599s of each other. I've been trying to figure this out recently and this article was the first one to appear, so just mentioning this for others to save them some time and headache.
Take a look at the Pusher Debug Console for your app. If you don't see your event triggered in there then it's either not reaching or is not being accepted by the Pusher REST API.
There aren't any issued raised about this Pusher PHP library.