Laravel 5.5 Send MAil - laravel

I a trying to send an email from localhost to my email but i alwasy get this error
Connection could not be established with host smtp.gmail.com [Une tentative de connexion a �chou� car le parti connect� n�a pas r�pondu convenablement au-del� d�une certaine dur�e ou une connexion �tablie a �chou� car l�h�te de connexion n�a pas r�pondu. #10060]
and i didn't found any solution
this is a screen shot for the error
this is the controller code
public function contact_sent(Request $request)
{
$emails = "mohamedfarjallah8#gmail.com";
$messages = "This body message......";
$subject = "This is subject from email";
$fromEmail = "mohamedfarjallah8#gmail.com";
$data = array('emails'=>$emails,'messages'=>$messages,'fromEmail'=>$fromEmail,'subject'=>$subject);
Mail::send([],$data, function ($message) use ($data) {
$message->from($data['fromEmail'],'SubText that show in header part of email');
$message->to($data['emails'])->setBody($data['messages']);
$message->subject($data['subject']);
$message->replyTo($data['fromEmail'],'Some text you can test this');
});
echo "Ok you can check your email";exit;
}
and this is the .env configuration
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=2525
MAIL_USERNAME=mohamedfarjallah8#gmail.com
MAIL_PASSWORD=**************
MAIL_ENCRYPTION=tls

You are using wrong mail port. Port 2525 is for Mailtrap, for Google it should be 587 for MAIL_PORT

Related

Laravel sendmail: 221 2.7.0 Error: I can break rules, too. Goodbye

I would like to send emails through a contact form in my Laravel 8 application. In my local instance everything works fine. When I upload it to the web server I receive the following error: 221 2.7.0 Error: I can break rules, too. Goodbye.
See screenshot of the error
My configuration
.env
MAIL_DRIVER=sendmail
MAIL_MAILER=sendmail
MAIL_HOST=localhost
MAIL_PORT=25
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=no-reply#example.de
MAIL_FROM_NAME="Example website contact form"
MAIL_RECIPIENT=my#email.de
Mail function in the contact controller
$toName = $request->name;
$toEmail = $request->email;
$toPhone = $request->phone;
$subject = $request->subject;
$message = $request->message;
if ($request->filled('phone')) {
$message = "Absender: $toName \nEmail: $toEmail \nTelefon: $toPhone" . "\n\n" . $message;
} else {
$message = "Absender: $toName \nEmail: $toEmail" . "\n\n" . $message;
}
// Send mail
Mail::raw($message, function ($message) use ($toName, $toEmail, $subject) {
$message->to(env('MAIL_RECIPIENT'))
->subject('Anfrage über das Kontaktformular')
->from($toEmail, $toName);
});
The message I can break rules, too. Goodbye. is emitted by the Postfix mail server when it received HTTP verbs (GET, POST, etc.) on an SMTP listener. If you're seeing this, it means you have an HTTP client attempting to talk to an SMTP server.
https://www.postfix.org/postconf.5.html#smtpd_forbidden_commands

Trying to send email to dynamic receiver with laravel

I was sending email to a static email and it was working but when I tried to send to a dynamic user getting data from the DB it returned this error: Expected response code 250 but got code "530", with message "530 5.7.1 Authentication required"
my sending email function:
public function send_email()
{
$getStaff=DB::table('users')
->OrderBy('id','DESC')
->first();
$staffacckey=$getStaff->access_key;
$staffemail=$getStaff->email;
$valueurl = env('APP_URL');
$info = array();
$info['url']=$valueurl;
$info['name']='tinox';
$info['msg']='test';
$info['key']=$staffacckey;
Mail::send('email.mail',$info, function($email) {
$ghost='no-reply#domain.com';
$admin='System Administrator';
$email->from($ghost, $admin);
$email->to($staffemail)->subject('email confirmation');
});
}
public function send_email()
{
$getStaff=DB::table('staff')
->OrderBy('staff_id','DESC')
->first();
$staffacckey=$getStaff->access_key;
global $staffemail;
$staffemail=$getStaff->email;
$valueOne = env('APP_URL');
$info = array();
$info['url']=$valueOne.':8080';
$info['name']='tinox';
$info['msg']='test';
$info['key']=$staffacckey;
$info['email']=$staffemail;
Mail::send('email.mail',$info,
function($email)use ($info){
$ghost='no-reply#magazinelte.com';
$admin='System Administrator';
$email->from($ghost, $admin);
$email->to($info['email'])->subject('Account activation');
});
}
just fixed the issue!! Passed variables inside the Mail function and change my env
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=*******#gmail.com
MAIL_PASSWORD=*******
MAIL_ENCRYPTION=tls

I am getting error when i am sending mail in laravel

I am getting error when i am sending mail at gmail id,I am using laravel 5.7,
I am getting this errot
Call to undefined function App\Http\Controllers\send()
and my controller code is :
public function postEmail(Request $r)
{
$data=[
'user_email'=>$r->user_email,
'user_name'=>$r->user_name,
'user_phone'=>$r->user_phone,
'user_desc'=>$r->user_desc,
];
Mail:send('mail.mail', $data, function($user_desc) use($data)
{
$message->from('sumitsaoni#gmail.com', 'Send by Sumit');
$messge->to($data['sumit123#gmail.com']);
$message->subject($data['user_desc']);
});
return redirect()->back()->with('message','successfully data insertd');
}
And My Route is
Route::resource('contact', 'ContactController');
Route::post('/postEmail', 'ContactController#postEmail');
My .env file mail gmail: .env
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=my_email (Using my email id)
MAIL_PASSWORD=password (using my email id password)
MAIL_ENCRYPTION=tls
You should try this:
use Mail;
Mail::send('mail', $data, function($user_desc) use($data)
{
$message->from('sumitsaoni#gmail.com', 'Send by Sumit');
$message->to($data['user_email']);
$message->subject($data['user_desc']);
});
Updated answer
Mail::send('mail', $data, function($message) use($data)
{
$message->from('sumitsaoni#gmail.com', 'Send by Sumit');
$message->to($data['user_email']);
$message->subject($data['user_desc']);
});
change
Mail:send('mail.mail', $data, function($user_desc) use($data)
to
Mail::send('mail.mail', $data, function($user_desc) use($data)
try this one
Mail:send to replace Mail::send

Mail Queue processed but the Laravel don't send email

The Mail::queue method processes the service but does not send the mail.Nothing arrives in the destination email. The redis is working normally.
$data = ['nome_prefeitura'=>$gestora->pessoa->nome,'empresa'=>$n->economico->pessoa->nome,'pessoa'=>$n->pessoa->nome,'link'=>$link,'nome_secretaria'=>'Secretaria Fazenda de Dom Joaquim.'];
Mail::queue('layout_email.email_nfse', $data, function ($m) use ($n) {
$m->from('nfe#mail.com.br', 'NFS-e');
$m->to($n->email_envio, $n->pessoa->nome)->subject('Notificação de emissão de NFS-e');
});
CACHE_DRIVER=redis
SESSION_DRIVER=redis
QUEUE_DRIVER=redis
MAIL_DRIVER=smtp
MAIL_HOST=mail.com.br
MAIL_PORT=25
MAIL_USERNAME=nfenfe#mail.com.br
MAIL_PASSWORD=****
MAIL_ENCRYPTION=null
I changed my email server and it worked.

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

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

Resources