I am trying to send email using Laravel via yahoo small business but I am getting This error please help me.
This is what I am getting an error(Image link)
My .env file
MAIL_DRIVER=smtp
MAIL_HOST=smtp.bizmail.yahoo.com
MAIL_PORT=465
MAIL_USERNAME=****#yahoo.com
MAIL_PASSWORD=*******
MAIL_ENCRYPTION=null
My Send email Code
public function index()
{
$this->sendMail('mails.subscribe', '******#****.**', '******#**.**',
'Testing', 'Test');
}
public function sendMail($bladeName, $from, $to, $subject, $body)
{
Mail::send(['html' => $bladeName], ['user' => $body], function
($message) use ($to, $subject, $from) {
$message->to($to)->subject($subject);
$message->from($from, 'Test');
});
}
Try to change the smtp port to : 587
Sorry for my other answer I overlooked your code.
your mail function is wrong that's why you are not connecting
try :
Mail::send('emails.welcome', ['key' => 'value'], function($message)
{
$message->to('foo#example.com', 'John Smith')->subject('Welcome!');
});
One more :
Mail::send('emails.welcome', $data, function($message)
{
$message->from('us#example.com', 'Laravel');
$message->to('foo#example.com')->cc('bar#example.com');
$message->attach($pathToFile);
});
Related
I try mailgun and it works to send an email, but the problem is when I run the function, it sent double email.
the function is like this:
public function sendEmail($id){
try{
$user= Users::find($id);
$data = array('username'=>$user->name, 'email'=>$user->email);
Mail::send('emails.hapstics', $data, function ($message) use($data){
$message->to($data['email'], $data['username'])->subject('Test Subject');
});
return redirect('leads');
}
catch(Exception $e){}
}
.env
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailgun.org
MAIL_PORT=587
MAIL_USERNAME=*hidden
MAIL_PASSWORD=*hidden
MAIL_FROM_NAME=*hidden
MAILGUN_DOMAIN=*hidden
MAILGUN_SECRET=*hidden
You can use this pattern for sending email.
$user = User::findOrFail($id);
Mail::send('emails.reminder', ['user' => $user], function ($m) use ($user) {
$m->from('hello#app.com', 'Your Application');
$m->to($user->email, $user->name)->subject('Your Reminder!');
});
You can send mail using Mailable as laravel docs https://laravel.com/docs/5.6/mail#generating-mailables
tutorial https://appdividend.com/2018/03/05/send-email-in-laravel-tutorial/
I set up a contact form which sends an email on completion using Laravel notifications, however it doesn't look like anything is being sent.
ROUTES
Route::post('/contact', 'ContactController#store');
CONTROLLER
public function store()
{
request()->validate([
'name' => 'required|max:255',
'email' => 'required|email|unique:contacts|max:255',
'message' => 'required|max:2000',
]);
$contact = Contact::create(
request()->only([
'name',
'email',
'message',
])
);
User::first()->notify(new SendContactNotification($contact));
return back()->with('success', 'Thank you, I will be in touch as soon as I can');
}
NOTIFICATION
protected $contact;
public function __construct($contact)
{
$this->contact = $contact;
}
public function toMail($notifiable)
{
return (new MailMessage)
->line($this->contact->name)
->line($this->contact->email)
->line($this->contact->message);
}
I do get the success message when I run it. However, nothing appears in my Mailtrap. Here's the mail section of the sanitised .env file:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=username
MAIL_PASSWORD=password
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS='admin#test.com'
MAIL_FROM_NAME='admin'
I can't see what I have done wrong. I also tried type hinting the contact in the notification like so:
public function __construct(Contact $contact)
{
$this->contact = $contact;
}
That didn't work unfortunately. I also thought it might be something to do with my computer not being set up to send emails using php, but I was under the impression that the env file would take care of that.
The contacts are being stored in the database ok, but no emails are being sent. Would anyone be able to help?
It was the port in the env file, I changed it to:
MAIL_PORT=465
and it worked!
I knew port 2525 wasn't working because of this answer: https://stackoverflow.com/a/45418259/5497241
I am trying to use Mail function in Laravel. Heres the code
public function basic_email(){
$data = array('name'=>"Virat Gandhi");
Mail::send(['text'=>'mail'], $data, function($message) {
$message->to('shanipasrooria#gmail.com', 'Tutorials Point')->subject
('Laravel Basic Testing Mail');
$message->from('m.usman5991#gmail.com','Virat Gandhi');
});
echo "Basic Email Sent. Check your inbox.";
}
I have made changes in .env file. Set everything, Heres my route.
Route::get('sendbasicemail','MailController#basic_email');
I get the following Error.
InvalidArgumentException in FileViewFinder.php line 137:
View [mail] not found.
You can try this code
Mail::send([], [], function ($message) {
$message->to('shanipasrooria#gmail.com', 'Tutorials Point')
->subject('subject')
->setBody('some body', 'text/html');
});
you can try this
$html = '<h1>Hi, welcome Virat!</h1>';
Mail::send([], [], function ($message) use ($html) {
$message->to('shanipasrooria#gmail.com', 'Tutorials Point')
->subject('Laravel Basic Testing Mail')
->from('m.usman5991#gmail.com','Virat Gandhi')
->setBody($html, 'text/html'); //html body
or
->setBody('Hi, welcome Virat!'); //for text body
});
Mail::send(['text'=>'mail']< here the mail should be a valid view file.
According to API Documentation, the Mailer Class should receive a String, Array Or MailableContract, Those reference a view. So you need to pass a valid view in the send method.
void send(string|array|MailableContract $view, array $data = [], Closure|string $callback = null)
I started a project using symfony 4 and the mailer doesn't work, however it should be easy.
before you ask, if i copy past the login and password from my code i'm able to log into my mail account, also i also tried with a netcourrier mail account, also the 2 way authentification is not active and i allowed less secure app to access the mail account.
Here's my conf:
in my .env:
MAILER_URL=gmail://*******#gmail.com:********#localhost
in my controller:
public function contact( \Swift_Mailer $mailer){
$message = (new \Swift_Message('Hello Email'))
->setFrom('*****#gmail.com')
->setTo('*******#gmail.com')
->setBody(
$this->renderView(
// templates/emails/registration.html.twig
'email/registration.html.twig',
array('url' => $url)
),
'text/html'
);
$mailer->send($message);
return $this->render(
'email/index.html.twig');}
and the error i get doing so is :
Connection could not be established with host smtp.gmail.com [ #0]
The problem is your connection SMTP with google, This is correct:
MAILER_URL=smtp://smtp.gmail.com:587?encryption=tls&username=userGmail&password=PassGmail
I have it defined as a service in App/Services, this is the code
<?php
namespace App\Services;
class Enviomail {
private $mailer;
public function __construct(\Swift_Mailer $mailer)
{
$this->mailer = $mailer;
}
public function sendEmail($to, $subject, $texto) {
$message = (new \Swift_Message($subject))
->setFrom('juanitourquiza#gmail.com')
->setTo($to)
->setBody(($texto),'text/html');
return $this->mailer->send($message);
}
}
And to use it I call it from the controller
use App\Services\Enviomail;
........
public function mailsolucion(Request $request, Enviomail $enviomail) {
if ($request->isMethod('POST')) {
$nombre=$request->get("nombre");
$email=$request->get("email");
$numero=$request->get("numero");
$empresa=$request->get("empresa");
$solucion=$request->get("solucion");
if (($nombre=="")||($email=="")||($numero=="")||($empresa=="")){
$this->addFlash(
'alert alert-danger',
'Toda la informaciĆ³n es obligatoria'
);
return $this->redirectToRoute('registro');
}
$emailreceptor="juanitourquiza#gmail.com";
$asunto="Soluciones gruporadical.com";
$texto=$this->renderView(
'emails/soluciones.html.twig',
array(
'nombre' => $nombre,
'email' => $email,
'numero' => $numero,
'empresa' => $empresa,
'solucion' => $solucion,
)
);
$enviomail->sendEmail($emailreceptor,$asunto, $texto);
$this->addFlash(
'alert alert-success',
'Pronto nos pondremos en contacto.'
);
return $this->redirectToRoute('registro');
}
return $this->render('AppBundle:App:contacto.html.twig');
}
Works perfect on Symfony 4.x
I think this is not an issue with the mailer, but with gmail. I copied your steps to try to connect through the smtp server of gmail, but got the same error. When using a different MAILER_URL (a different smtp-server) in the .env file, everything works like it should.
Below are my mail code and configuration.
The issue which I'm facing is that mail() is not working, but I'm getting the output as mail sent (from code,when 'pretend' => false,) and not sent ('pretend' => true, and I also get "server.INFO: Pretending to mail message to:soandso#mail.com " in the log file ).What could be the issue? Same code is working for another site hosted with the same provider( GoDaddy)
$mail= Mail::send($view, $data, function ($message) use ($email, $subject, $data) {
if (isset($data['senderEmail'])) {
$message->from($data['senderEmail'], $data['senderFullname']);
}else{
$defult=\DB::table('settings')->select('value')->where('option','=','defaultMail')->first();
$message->from($defult->value, 'mailFrom');
}
if (isset($data['attachment'])) {
$message->attach($data['attachment']);
}
$message->to($email)->subject($subject);
});
if($mail){
dd("mail sent");
}else{
dd("not sent");
}
.env file
MAIL_DRIVER=sendmail
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=XXXXXXXX#gmail.com
MAIL_PASSWORD="XXXXXXXX"
MAIL_ENCRYPTION=tls
SENDERS_EMAIL=XXXXXXXX#gmail.com
SENDERS_NAME=afsal
config/mail.php
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,