IronMq : mail doesn't send but the queue is working - laravel

I use IronMQ for to send my email since (laravel framework)
1. for signup email (it's oki with my SMTP and IronMQ)
2. Notification email (between users).
I'm a problem with the n°2 : iron receive the queue and It work but my SMTP don't receive the message for to send it.
I don't understand why because the config SMTP and IronMQ does not change between the two (Mail::queue)
PHP Code :
/****************************
Notification email (buged)
*****************************/
$emailTo = $product->user->email;
$emailFrom = $emailSend;
$data = Input::only('messageSend', 'name');
$data['product'] = $product;
Mail::queue('emails.products.iWant', $data, function($mail) use($emailTo, $emailFrom){
$mail
->from($emailFrom)
->to($emailTo)
->subject("Je suis intéressé(e) par votre produit");
});
/****************************
Signup email (it's oki)
*****************************/
$data = array('id' => $id, 'name' => $name, 'key' => $activation_code);
Mail::queue($view, $data, function($mail) use($email, $subject) {
$mail
->to($email)
->subject($subject);
});
With Mail::queue it's no possible to keep the message_id or it's Success or failed ?
Thanks

Related

Laravel sending e-mails to new registered users

I'm trying to send e-mails to new users. I made changes in my env. file. I am using a gmail.com mail service. I want to send e-mails to users including their name. Ex:
Hi John, your registration is succesful!
Here John part will be user name.
my code is here in RegistrationController:
protected function create(array $data)
{
$user = User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
]);
$to_name = $data['name'];
$to_email= $data['email'];
$body =[];
$mailData=array('body'=>$body);
Mail::send('email.email-register', $mailData, function($message) use ($to_name, $to_email ){
$message->to($to_email, $to_name)->subject('Registration is succesfull!');
$message->from(env('MAIL_USERNAME'));
});
return $user;
}
Also i am using a mail template. I want to send user as variable to the view. How do i do that?
1- You need to run command php artisan make:mail RegisterMail
2- Add Library use App\Mail\RegisterMail;
Mail::to('YourEmail#gmail.com')->send(new RegisterMail($mailData));
3- Create a new Data Member in your App\Mail\RegisterMail.php Class
public $mailData;
public function __construct($mailData)
{
$this->mailData = $mailData;
}
4- Add this in your App\Mail\RegisterMail.php
public function build(){
return $this->from('youremail#gmail.com','your name')->replyTo('youremail#gmail.com')->subject($this->mailData['subject'])->view('email')->with('mailData',$this->mailData);
}

Relating email replies to original email (e-mail thread) with Sendgrid

I'm sending e-mails with Sendgrid. When the recipients reply to the mails, Sendgrid will parse the reply and POST to my webhook.
How can I relate the reply to the original message, so that I have a message thread?
I'm thinking that this may be possible using X-SMTPAPI headers and unique_args.
Update:
I think this is how I did it (but it was a while ago)
$arguments = ['unique_args' => [
'sentMessage_id' => $this->sentMessage->id,
'tenant_id' => \app('currentTenant')->id,
]];
$header = \json_encode($arguments);
$this->withSwiftMessage(function ($message) use ($header) {
$thread = $this->sentMessage->message->thread;
$headers = $message->getHeaders();
$headers->addTextHeader('X-SMTPAPI', $header);
$headers->addTextHeader('References', "<{$thread->first_mail_reference}>");

How to add more parameter on controller laravel mail

I want to send email using Laravel and success with this code
Mail::to($email)->send(new SendMail($name))
Now I want to send more parameter like subject with this code, but didn't work.
No error message but email not being sent.
Mail::send(new SendMail($name function($message) use ($email){
$message->to($email)->subject('Verify your Account');
}));
Any suggestions? Thanks in advance!
You can use something like that
$template = 'view.email';
$paramets = ['data'=>$data];//Your to value to print in email
$email = 'to#email.com'// to email
$cc = 'cc#email.com' // or null
$toName = 'John Doe' // or null
$subject = 'Verify your Account';
Mail::send($template, $parameters, function($message) use($email,$cc,$toName,$subject) {
$message->from(env('sender'), env('nameSender'));
if($cc) $message->cc($cc);
$message->to($email, $toName)
->subject($subject);
});
I am using a generic method. So i can use this method to all emails that i need to send

Notification being sent even after setting Notification::fake()

I am testing notifications in my application and here is my code to test that Admin receives a notification:
public function testAdminReceivesNotifications()
{
Notification::fake();
$admin = $this->preload();
$taskTitle = str_random();
$project = Project::first();
$projectMember = factory(\App\Models\User::class)->create([
'type' => 'INTERNAL'
]);
$project->users()->save($projectMember, [
'project_permissions' => [1,2,3,4,5,6,7,8,10]
]);
$this->browse(function (Browser $browser, Browser $secondBrowser) use($admin, $taskTitle, $project, $projectMember) {
$this->login($browser, $admin)
->visit("p/{$project->slug}")
->waitForText('Add Task')
->click("#add-task")
->waitForText('Create Task')
->type('#task-title', $taskTitle)
->keys('[trix-id="1"]', str_random())
->press('SAVE TASK')
->waitForText('Post anyway')
->press('Post anyway')
->waitForText('Unscheduled')
->pause(1000)
->assertSee('Unscheduled')
->assertSee($taskTitle);
$task = Project\Todo::where('title', $taskTitle)->first();
$this->login($secondBrowser, $projectMember)
->visit("p/{$project->slug}/tasks/{$task->id}")
->waitForText($task->title)
->keys('trix-editor', str_random() . "message by another member")
->press('Reply')
->pause(2000);
});
Notification::assertSentTo($admin,TodoMessageCreated::class);
}
The problem I am getting - is even though I do set Notification fake - the email is being sent (I use log as Mail driver in my tests and I see the email in the logs. I have checked - an I can assure that TodoMessageCreated was triggered.

When i am trying to send mail from contactUS form getting this error using swiftmailer in Laravel 5.2

when i am trying to send Mail through Contact Us Form receiving this Error
"Address in mailbox given [] does not comply with RFC 2822, 3.6.2."
I try search to find solution but I cannot find one. I edited config/mail.php
public function sendContactInfo(ContactMeRequest $request)
{
$data = $request->only('name', 'email');
$emailto="******#gmail.com";
$data['messageLines'] = explode("\n", $request->get('message'));
Mail::send('publicPages.contactus', $data, function ($message) use ($emailto) {
$message->subject('Contact Us Form: ')
->to(config('blog.contact_email'))
->replyTo($data['email']);
});
return back()
->withSuccess("Thank you for your message. It has been sent.");
}
with configuration file
i am following this tutorial
Laravel Send Mail
use $data['email']
Mail::send('publicPages.contactus', $data, function ($message) use ($emailto,$data['email']) {
$message->subject('Contact Us Form: ')
->to(config('blog.contact_email'))
->replyTo($data['email']);
});

Resources