Im trying to send email from my local host using sendgrid, packages s-ichikawa 2.1.0 , laravel 5.7.29, Im getting this Error
Client error: POST https://api.sendgrid.com/v3/mail/send resulted in a 403 Forbidden response: {"errors":[{"message":"The from address does not match a verified Sender Identity. Mail cannot be sent until this error (truncated...) *
Same code working on other project in API , but on localhost Im this error.
MY Controller Code:
$email = 'umermajeed93#hotmail.com';
$name = 'Umer Majeed';
Mail::to($email)->send(new SendMailable($name ,$email))
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
use Sichikawa\LaravelSendgridDriver\SendGrid;
class SendMailable extends Mailable
{
use Queueable, SerializesModels;
use SendGrid;
public $name;
public $code;
public $email;
/**
* Create a new message instance.
*
* #return void
*/
public function __construct($name,$email)
{
$this->name = $name;
$this->email = $email;
}
/**
* Build the message.
*
* #return $this
*/
public function build()
{
$address = 'noreply#retailplatform.com';
$subject = 'New Ad';
return $this
->view('Admin.email')
->subject($subject)
->from($address)
->to([$this->email])
->sendgrid([
'personalizations' => [
[
'substitutions' => [
':myname' => 's-ichikawa',
],
],
],
])->with('name',$this->name);
}
}
in the test environment only emails are sent to your test account, which you set up in the .env file:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=
MAIL_PASSWORD=
in production you could already send emails to the recipient of your choice, but on the local server you cannot
Related
I'm developing a new Laravel application. When I'm using mail to send messages via laravel schedule command, I'm getting the following error:
Swift_TransportException with message 'Process could not be started
[The system cannot find the path specified. ]
This is my Command file.
EmailReminder.php
<?php
namespace App\Console\Commands;
use App\ScheduleMeeting;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Mail;
use Modules\User\Emails\MentorEmailReminder;
class EmailReminder extends Command
{
/**
* The name and signature of the console command.
*
* #var string
*/
protected $signature = 'reminder:emails';
/**
* The console command description.
*
* #var string
*/
protected $description = 'Send email notification to user about reminders.';
/**
* Create a new command instance.
*
* #return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* #return int
*/
public function handle()
{
$date = now()->tz('Asia/Singapore')->addDay(); // Current date is added one day
$newDate = $date->format('Y-m-d g:i A');
$tomorrow_meetings = ScheduleMeeting::where('start_time','=', $newDate)
->where('status',1)
->where('meeting_type',0)
->get();
$data = [];
foreach($tomorrow_meetings as $meeting){
$data[$meeting->mentor_id][] = $meeting->toArray();
}
foreach($data as $mentorId => $reminders){
$this->sendEmailToUser($mentorId, $reminders);
}
}
private function sendEmailToUser($mentorId, $reminders){
$user = \App\User::find($mentorId);
Mail::to($user)->send(new MentorEmailReminder($reminders));
}
}
This is my email file.
MentorEmailReminder.php
<?php
namespace Modules\User\Emails;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class MentorEmailReminder extends Mailable
{
use Queueable, SerializesModels;
public $reminders;
public function __construct($reminders)
{
$this->reminders = $reminders;
}
public function build()
{
$subject = 'Reminder: Mentoring Session with';
return $this->from(setting_item("email_from_address"), 'Uplyrn')->subject($subject)->view('User::emails.mentor-email-reminder')->with([
'reminders' => $this->reminders,
]);
}
}
This is .env file.
MAIL_DRIVER=sendmail
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
I am taking over a project and a client wants me to add a mailing feature like a gmail with inbox, sent messages and the user can also reply to emails from outside the system and the people receiving it can also reply. I have basic knowledge on laravel but this is my first time creating a feature like this can anyone give a stepping stone. This project has a VUE.js as a front end and a laravel as an API
Step -1: Create a Mail using,
php artisan make:mail MailName
Check the file MailName.php inside App/Mail/ directory
Step - 2: Create a function to send the email with the requested data.
public function sendMail(Request $request){
$data = [
'value1'=> $request->value1,
'value2'=> $request->value2,
'value3'=> $request->value3
];
//You can add any function like storing the values into db.
if(someconditions){
\Mail::to('emailid#domainname.com')->send(new MailName($data));
return back()->with('success', 'Email has been sent successfully!');
}
else
{
return back()->with('error', 'Something went wrong!');
}
}
Step - 3: Open the App/Mail/MailName.php
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
use Illuminate\Mail\Mailables\Address;
//You can include your model here.
class DeleteResponseMail extends Mailable
{
use Queueable, SerializesModels;
/**
* Create a new message instance.
*
* #return void
*/
public $data;
public function __construct($data)
{
$this->data = $data;
}
/**
* Get the message envelope.
*
* #return \Illuminate\Mail\Mailables\Envelope
*/
public function envelope()
{
return new Envelope(
from: new Address('fromemail#somedomain.com', 'From Email Name'),
replyTo: [
new Address('admin#yourdomain.com', 'Your email name'),
],
subject: 'Email Subject',
);
}
/**
* Get the message content definition.
*
* #return \Illuminate\Mail\Mailables\Content
*/
public function content()
{
return new Content(
view: 'emails.mail',
);
}
/**
* Get the attachments for the message.
*
* #return array
*/
public function attachments()
{
return [];
}
}
Step - 4: Create mail.blade.php under resources/views/emails
Hi $data['value1'],
We have received your application. Thanks!
Step - 5: Open your .env file and add the email configurations.
MAIL_MAILER=enteryourmailerhere (ex.smtp)
MAIL_HOST=enteryourmailhosthere (ex.smtp.gmail.com)
MAIL_PORT=entertheport (ex. 25)
MAIL_USERNAME=emailid#yourdomain.com
MAIL_PASSWORD=emailpassword
MAIL_ENCRYPTION=""
MAIL_FROM_ADDRESS="fromemail#yourdomain.com"
MAIL_FROM_NAME="${APP_NAME}"
That's all! It should work.
I have some notifications (that get sent out to SendGrid) and I am using table queues.
I build my notification as below
$data = [
'email_message' => $message,
'subject' => $request->subject,
'email' => $request->email
];
$user->notify(new EmailGeneralNotification($data));
My Notification looks like this;
<?php
namespace App\Notifications;
use Illuminate\Notifications\Notification;
use NotificationChannels\SendGrid\SendGridChannel;
use NotificationChannels\SendGrid\SendGridMessage;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
// use Illuminate\Queue\SerializesModels;
use App\Models\NotificationTemplate;
class EmailGeneralNotification extends Notification implements ShouldQueue
{
use Queueable;
// use SerializesModels;
protected $data;
/**
* Create a new notification instance.
*
* #return void
*/
public function __construct(array $data) {
$this->data = $data;
}
public function via($notifiable)
{
return [
SendGridChannel::class,
];
}
public function toSendGrid($notifiable)
{
$reference = 'internal_general_email';
$template = NotificationTemplate::where('reference',$reference)->latest('updated_at')->first();
if(!$template)
{
dd("No template was found for " . $reference);
}
return (new SendGridMessage($template->template_id))
/**
* optionally set the from address.
* by default this comes from config/mail.from
* ->from('no-reply#test.com', 'App name')
*/
/**
* optionally set the recipient.
* by default it's $notifiable->email:
* ->to('hello#example.com', 'Mr. Smith')
*/
->payload([
"subject" => (array_key_exists('subject', $this->data)) ? $this->data['subject'] : '',
"email_message" => (array_key_exists('email_message', $this->data)) ? $this->data['email_message'] : '',
]);
}
}
This gets sent via a SendGrid notification type.
The funny this is that when I remove the implements ShouldQueue and use Queueable and run my function everything works fine.
When I enable the queue I get the below;
[2022-10-30 08:34:08] local.ERROR: Declaration of Ramsey\Uuid\Uuid::unserialize(string $data): void must be compatible with Serializable::unserialize($serialized) {"exception":"[object] (Symfony\\Component\\ErrorHandler\\Error\\FatalError(code: 0): Declaration of Ramsey\\Uuid\\Uuid::unserialize(string $data): void must be compatible with Serializable::unserialize($serialized) at /var/www/html/vendor/ramsey/uuid/src/Uuid.php:307)
[stacktrace]
#0 {main}
"}
I have updated php to v8 and got Laravel to 8.83.25 but still no joy
I have an laravel 7 application and use smtp with google services to send my emails.
However some clients receive the emails with attachments, but no body. The content of the email is completely blank. Most mail platforms (hotmail, outlook, gmail, mail on mac) receive the complete email. It's just some mail providers receive the email without a body.
I believe this might have to do with some security measures or not supporting HTML emails.
How can I ensure that also these clients receive my emails?
I use .blade.php files to send my emails.
example of one of my email files:
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class CandidateMail extends Mailable
{
use Queueable, SerializesModels;
/**
* Create a new message instance.
*
* #return void
*/
public function __construct($message_details)
{
//
$this->message_details = $message_details;
}
/**
* Build the message.
*
* #return $this
*/
public function build()
{
$email = $this->view('mail/candidate')
->subject($this->message_details['subject'])
->with(['message_details' => $this->message_details]);
if ($this->message_details['attachments']) {
$email->attachFromStorage($this->message_details['attachments']);
}
return $email;
}
}
Fix for outlook (desktop).
replaced my divs with table/tr/td. Now email content is displayed to clients with outlook (desktop).
you had to build your constructor the variable $message_details does not return anything,
public $message_details = "";
Need to declare public property public $message_details here details
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class CandidateMail extends Mailable
{
use Queueable, SerializesModels;
public $message_details;
/**
* Create a new message instance.
*
* #return void
*/
public function __construct($message_details)
{
//
$this->message_details = $message_details;
}
/**
* Build the message.
*
* #return $this
*/
public function build()
{
$email = $this->view('mail/candidate')
->subject($this->message_details['subject'])
->with(['message_details' => $this->message_details]);
if ($this->message_details['attachments']) {
$email->attachFromStorage($this->message_details['attachments']);
}
return $email;
}
}
I can send emails to a lot of recipients but the problem is I am using a business email which I'm subscribe to my web host, the problem is when I send 1 email to a lot of recipients my web host automatically suspends my email's outgoing which technically I'm having problems with right now, so I tried using mailing list but it won't send emails to my recipients using the Mail(), but it works when sending a mail to mailist-join#domain.com.
Controller:
public function imail($request){
$dataEmail = [
'date' => $request->date,
'time_start' => $request->start,
'time_end' => $request->end,
'duration' => abs(strtotime($request->end) - strtotime($request->start))/(60*60),
'areas' => Purifier::clean($request->areas),
'reason' => Purifier::clean($request->activities)
];
$emails = UserEmail::where('email','!=','')->select('email')->get()->pluck('email');
$subject = 'ADVISORY (' . date("F j, Y",strtotime($request->date)) .')';
foreach ($emails as $email) {
Mail::to($email)
->send(new SendToAll($dataEmail,$subject));
}
}
SendToAll Mail
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class SendToAll extends Mailable implements ShouldQueue
{
use Queueable, SerializesModels;
// public $afterCommit = true;
public $data,$subject;
/**
* Create a new message instance.
*
* #return void
*/
public function __construct($data,$subject)
{
$this->data = $data;
$this->subject = $subject;
}
/**
* Build the message.
*
* #return $this
*/
public function build()
{
return $this->subject($this->subject)
->from('myemail#domain.com','Me')
->view('pages.imail')
->with('data',$this->data);
;
}
}
I also tried supervisor but to no avail. I'm using Windows Server 2012.
You have to use like below code
Mail::to($email)->cc(['mail1','mail2','mail3'])->send(new SendToAll($dataEmail,$subject));