Laravel Send Reset Password Using Sentry - email

I install laravel with Sentinel(Sentry) but i dont know how to send a password reset using email template from sentinel/Sentry
this is my controller
$data = array(
'hash' => Hash::make($user->id),
"code" => $user->getResetPasswordCode()
);
$send = Mail::send('sentinel.emails.reset', $data, function($message) use($data) {
$message->to($data["email"], $data["email"])->subject('Info');
});
how to get the code??

Using Sentry
$user = Sentry::findUserByLogin($request->input('email'));
$user->getResetPasswordCode()

Related

Message: Call to undefined method CI_Email::get_emails() codeigniter 3

I try build function in controller Codeigniter 3 to read emails from inbox and insert to database.
`public function read_emails() {
// Load the email and database libraries
$this->load->library('email');
// Connect to the POP3 server
$config = array(
'protocol' => 'pop3',
'pop3_host' => 'pop.gmail.com',
'pop3_user' => 'xxxxxxxxxxxx',
'pop3_pass' => 'xxxxxxxxxxxxxxxx',
'pop3_port' => 995,
'pop3_encryption' => 'ssl'
);
$this->email->initialize($config);
// Retrieve emails from the inbox
$emails = $this->email->get_emails();
// Loop through the emails
foreach ($emails as $email) {
// Check if the email was received within the last 24 hours
$received_time = strtotime($email['received_time']);
$current_time = time();
if ($current_time - $received_time <= 86400) {
// Check if the email already exists in the database
$this->db->where('email', $email['email']);
$query = $this->db->get('contacts');
if ($query->num_rows() == 0) {
// Insert the email into the database
$data = array(
'email' => $email['email'],
'subject' => $email['subject'],
'message' => $email['message']
);
$this->db->insert('contacts', $data);
}
}
}
}`
When I run this controller I get output:
Message: Call to undefined method CI_Email::get_emails()
Can anyone please help me debug this issue? Very important.
line 43:
// Retrieve emails from the inbox
$emails = $this->email->get_emails();
I don't know if codeigniter3's email class has such a get_emails() function, or if you can retrieve emails from the inbox.
Please check the official documentation: https://codeigniter.com/userguide3/libraries/email.html
If it is a custom class/plugin/addon, you should either publish its code or submit a link to the repo

Laravel-why admin receives every email message?

I am working on a web application with multiple users, and I have some issue with sending emails.
Sending is working fine, no problems, but the issue is that every mail interaction between visitors and users is sent to admin email address stated in env file. I am using gmail for sending, Laravel 8.
For example, visitor A has sent a message to user B. User B received mail correctly, but also admin received message.
Thanks for help.
Here is my EmailsController
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Mail;
class EmailsController extends Controller
{
public function send(Request $request)
{
function sentence_case($string) {
$sentences = explode(" ",$string);
$sentences = array_reverse($sentences);
$new_string = '';
foreach ($sentences as $key => $sentence) {
$new_string = ucfirst(mb_strtolower(trim($sentence)))." ".$new_string;
}
return $new_string;
}
$this->validate($request, [
'ime' => 'required', //visitor name
'email' => 'required', // visitor email address
'poruka' => 'required' //visitor message
]);
$ime = $request->get('ime');
$ime = sentence_case($ime);
$email = $request->get('email');
$poruka = $request->get('poruka');
Mail::send('emails.message', [
'name' => $ime,
'email' => $email,
'comment' => $poruka ],
function ($m) use ($email) {
$m->from($email);
$m->to('usersemail#yahoo.com', 'MyApp')
->subject('Website Contact Form');
});
/* usersemail#yahoo.com is registered user email address different from aplication admin/owner email addres stated in env file, but admin receives this message */
if (Mail::failures()) {
return response()->Fail('Sorry! Please try again latter');
}else{
return back()->with('success', 'Thanks for contacting me, I will get back to you soon!');
}
}
}

How to send email with dynamic sender in laravel?

I am creating a simple contact us from in Laravel.
I set up .env with my Gmail account. I can send email from Laravel with my email address, no problem with this.
But, I want to send email from sender address who is sending the message form contact us form.
Here is my code in controller:
public function sendMessage(Request $request)
{
$this->validate($request,[
'email'=>'required|email',
'subject'=>'required',
'body'=>'required|max:150'
]);
$body = $request['body'];
Mail::send('emails.support',['body' => $body], function($message){
$email = Input::get('email');
$subject = Input::get('subject');
$message->sender($email);
$message->to('smartrahat#gmail.com','Mohammed');
$message->subject($subject);
});
return redirect('contactUs');
}
Though, I am getting email address form contact us form, the email always sent form my email account which I configured in .env
I would have done some things different. I guess $body is the email-text? You should put this in a array and add it as a parameter in Mail::send (or directly put $request->all() as a parameter.
Also, inside of the closure of Mail, i don`t thinks its very nice to put logic there (like $email=Input::get). It does not look right if you ask me.
Didn`t test this code, but this should work:
public function sendMessage(Request $request)
{
$this->validate($request,[
'email' => 'required|email',
'subject' => 'required',
'body' => 'required|max:150'
]);
$data = [
'email' => $request->input('email'),
'subject' => $request->input('subject'),
'body' => $request->input('body')
];
Mail::send('emails.support', $data, function($message) use ($data)
{
$message->from($data['email']);
$message->to('smartrahat#gmail.com','Mohammed');
$message->subject($data['subject']);
});
return redirect('contactUs');
}
Because you add $data as as 'use', you can access this data inside the closure. The $data send as a parameter, can be used in the email blade. In this example, you can access the data like this: $email , $subject , $data, in blade these will output the values.
But you can also do it like this:
Mail::send('emails.support', $request->all(), function($message) use ($data)
public function reset_password(Request $request)
{
$user=User::whereEmail($request->email)->first();
if(count($user) == 1)
{
$data = array('name'=>"Virat Gandhi");
$subject=$request->email;
mail::send(['emails'=>'reset_set'],$data,
function($message)use($subject)
{
$message->from('your#gmail.com','kumar');
$message->to($subject);
$message->subject($subject);
});
echo "Basic Email Sent. Check your inbox.";
}
}
foreach ($emails as $value1)
{
$to[]=implode(',',$value1['0']);
}
$subject=$request->input('sub');
$mailsend=Mail::send('email.subscribe',$mail_content,
function($message)use($to,$subject)
{
$message->from('ganarone#ganar.io','Ganar');
$message->to($to);
$message->subject($subject);
});

Send mail to multiple recipients from data base using zf2

This is my first application using Zend Framework 2. I want to send an email to recipients retreived from a database, but each time my code displays an error. This is my code:
$user = new Container('user');
$db = $this->getServiceLocator()->get('db1');
if (!$user->offsetExists('id')) {
$idconnected = '0';
} else {
$idconnected = $user->offsetGet('id');
$mail = $db->query("SELECT email FROM user WHERE id =" . $idconnected)->execute()->current();
$message = new Message();
$message->addTo($mail, 'eee#web.com')
->addFrom('xxxx#gmail.com')
->setSubject('Invitation à l’événement : Soirée Latino');
$message->addCc('xxxx#hotmail.com')
->addBcc("xxxx#hotmail.com");
// Setup SMTP transport using LOGIN authentication
$transport = new SmtpTransport();
$options = new SmtpOptions(array(
'host' => 'smtp.gmail.com',
'connection_class' => 'login',
'connection_config' => array(
'ssl' => 'tls',
'username' => 'xxxx#gmail.com',
'password' => '*********'
),
'port' => 587,
));
$html = new MimePart('<b>Invitation for the event: Latin Night, orgonized by Mr. Jony Cornillon <i>Date : 06/04/2015</i></b>');
$html->type = "text/html";
$body = new MimeMessage();
$body->addPart($html);
//$body->setParts(array($html));
$message->setBody($body);
$transport->setOptions($options);
$transport->send($message);
}
And this is the error:
5.1.2 We weren't able to find the recipient domain. Please check for any
5.1.2 spelling errors, and make sure you didn't enter any spaces, periods,
5.1.2 or other punctuation after the recipient's email address. a13sm19808164wjx.30 - gsmtp
I tried with this code, and now it works fine :
foreach ($mail as $recip) {
$message->addTo($recip);
$message->addTo('samehmay#hotmail.com', 'eee#web.com')
->addFrom('maysameh0#gmail.com')
->setSubject('Invitation à l’événement : Soirée Latino');
}

Send mail via MailGun in CakePHP

i run a cloud app (using CakePHP) on Rackspace and i wanna send emails using cakephp.
I used this: https://github.com/kochb/cakephp-mailgun
but it returns me an
"Could not send email.
Error: An Internal Error Has Occurred."
error.
The way i try to send an email is with the following code:
$Email = new CakeEmail();
$from = $this->request->data['Mail']['from'];
$to = ($this->request->data['Mail']['to']);
$subject = $this->request->data['Mail']['subject'];
$message = $this->request->data['Mail']['message'];
$Email->sender($from, 'TestName');
$Email->from($from)
->bcc($to)
->replyTo($from)
->subject($subject)
->send($message);
$this->Session->setFlash('On the way to recipient');
$this->redirect(array('action' => 'index'));
I have edited the Config/Email.php file inserting the MailGun API credentials etc.
What's possibly going on? Can you find out why this happens?
Thanks in advance!
(I was having the same errors you were)
The BasicTransport didn't have the right "pre-processing" nor the appropriate response handling.
I copied over the functionality from CurlTransport and it works for me now.
Specifically, we needed:
$post = array();
$post_preprocess = array_merge(
$email->getHeaders(array('from', 'sender', 'replyTo', 'readReceipt', 'returnPath', 'to', 'cc', 'bcc', 'subject')),
array(
'text' => $email->message(CakeEmail::MESSAGE_TEXT),
'html' => $email->message(CakeEmail::MESSAGE_HTML)
)
);
foreach ($post_preprocess as $k => $v) {
if (! empty($v)) {
$post[strtolower($k)] = $v;
}
}
and then:
$response = $http->post($url, $post, $request);
if ($response === false) {
throw new SocketException("Mailgun BasicTransport error, no response", 500);
}
$http_status = $response->code;
if ($http_status != 200) {
throw new SocketException("Mailgun request failed. Status: $http_status, Response: {$response->body}", 500);
}