I struggle to send a mail inside a botman reply.
I use mailhog, with botman 2.0 and laravel 5.7.
I've tested mailhog with simple php code , it work.
Here my env file config :
MAIL_DRIVER=smtp
MAIL_HOST=localhost
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
The conversation start here :
<?php
namespace App\Conversations\SASI\CreationTicket;
//use Validator;
use Illuminate\Support\Facades\Validator;
use BotMan\BotMan\Messages\Incoming\Answer;
use BotMan\BotMan\Messages\Conversations\Conversation;
use App\Conversations\SASI\CreationTicket\EndTicketResume;
class EndTicket extends Conversation
{
public function askProblem()
{
$this->ask('Décrivez succintement votre problème :', function(Answer $answer) {
$this->bot->userStorage()->save([
'problem' => $answer->getText(),
]);
$this->askEmail(); //passe à la fonction suivante
});
}
public function askEmail()
{
$this->ask('Quel est votre email?', function(Answer $answer) {
$validator = Validator::make(['email' => $answer->getText()], [
'email' => 'email',
]);
if ($validator->fails()) {
return $this->repeat('Cette email ne semble pas valide. Entrez un email valide.');
}
$this->bot->userStorage()->save([
'email' => $answer->getText(),
]);
$this->askMobile();
});
}
public function askMobile()
{
$this->ask('Quel est votre numéro pro?', function(Answer $answer) {
$this->bot->userStorage()->save([
'mobile' => $answer->getText(),
]);
$this->say('Merci');
//renvoi a une autre conversation app\Conversations\SelectServiceConversation.php
$this->bot->startConversation(new EndTicketResume());
});
}
public function run()
{
$this->askProblem();
}
}
As you can see the bot say "Merci" (thanks) and go to another conversation. If add my mail code the bot stop before he say "Merci"
So the next conversation :
<?php
namespace App\Conversations\SASI\CreationTicket;
use Illuminate\Support\Facades\Mail;
use BotMan\BotMan\Messages\Conversations\Conversation;
class EndTicketResume extends Conversation
{
public function confirmTicket()
{
$user = $this->bot->userStorage()->find();
$message = '------------------------------------------------ <br>';
$message .= 'Probleme : '.$user->get('problem').'<br>';
$message .= 'Email : '.$user->get('email').'<br>';
$message .= 'Tel : '.$user->get('mobile').'<br>';
$message .= '------------------------------------------------';
$this->say('Votre demande va être envoyé. <br><br>'.$message);
$email = $user->get('email');
$data = [
'first' => 'test',
'last' => 'TEST'
];
// send email with details
Mail::send('emails.justshoot', $data, function($message) use ($email) {
$message->subject('Welcome');
$message->from($email, 'Just Shoot Upload');
$message->to('myemail@gmail.com')->cc('test@gmail.com');
});
}
/**
* Start the conversation.
*
* @return mixed
*/
public function run()
{
$this->confirmTicket();
}
}
If I remove this
Mail::send('emails.justshoot', $data, function($message) use ($email) {
$message->subject('Welcome');
$message->from($email, 'Just Shoot Upload');
$message->to('myemail@gmail.com')->cc('test@gmail.com');
});
The bot say his last message, all is ok. But if I add this code , as I said previously, the bot won't even go to another conversation.
What I am doing wrong ?