I need to set SMTPUser, Pass and Host in Email Class as variables taken from MySQL database. I can set them in Controllers like this:
$configModel = new ConfigModel();
$config = $configModel->where('id', 1)->find();
$user = $config[0]['mail_user'];
$pass = $config[0]['mail_pass'];
$server = $config[0]['mail_server'];
but how to use them in Email Class? Should I set them as some session variables and access them in Email class? Is it safe?
Additionaly, I've also tried doing email initialization in my Controller like this:
$emailConfig['SMTPUser'] = $user;
$emailConfig['SMTPPass'] = $pass;
$emailConfig['SMTPHost'] = $server;
$emailConfig['SMTPPort'] = 465;
$emailConfig['SMTPCrypto'] = 'ssl';
$emailConfig['protocol'] = 'smtp';
$email->initialize($emailConfig)
but it gives me error:
Sender address rejected: need fully-qualified address
So logging to email is successful, but it cannot sent mails for some reason. Is this option missing some configuration?
I'd rather use default Email Class provided by CI4 with database variables.
Related
my session driver is set to database,
.env => SESSION_DRIVER=database
I have made a model for session and I access to a session of another user by user_id like this :
use App\Models\Session;
$payload = Session::where('user_id', $request->user_id)->pluck('payload');
$payload = unserialize(base64_decode($payload));
if (!isset($payload['cart'])) {
dd($payload['cart']);
}
now I want to session()->forget('cart') of that specific user not the current user, but the payload field is decode by base64 and serialized.
how to do that?
thanks
I tried a few things and by changing the id it works :
// Get the store from laravel (encrypted or not)
$store = session()->getDrivers()['database'];
// Change the id
$store->setId($id);
// Start the session
$store->start();
// Remove the item
$store->pull('cart');
// Save the session in database
$store->save();
i don't think it's something that laravel support, so this might break in the future
Yes I found it.
the problem is to displacement of serialize() and base64_encode() after unset($payload['cart']) like this:
use App\Models\Session;
$session = Session::where('user_id', $request->user_id)->first();
$payload = unserialize(base64_decode($session->payload));
if (!isset($payload['cart'])){
unset($payload['cart']);
}
$session->payload = base64_encode(serialize($payload));
$session->save();
I am facing the issue of localhost/joomla is not showing login page, just show word Error
I have attached permission details and other corresponding files. Please help me to solve this issue.
Thankyou for your time.
Seems like the database the site it's not connected.
Check your configuration.php (in the root of the site) for this parameters:
public $dbtype = 'mysqli'; // Driver you are using to connect to the MySQL database.
public $host = 'localhost'; // The host for the database. If it's in the same server, it's ok like this.
public $user = 'root'; // Username for the database
public $password = 'root'; // Password of the database
public $db = 'NAME_OF_THE_DATABASE'; // Name of the database.
I have a situation where an app is sending its mails with PHPMailer and next configuration:
$mail->isSMTP();
$mail->Host = 'myhost.dev';
$mail->SMTPAuth = false;
$mail->setFrom($from, $from_name);
$mail->addAddress($to, $to_name);
if ($replyTo != '') $mail->addReplyTo($replyTo, $replyToName);
$mail->isHTML(true);
$mail->CharSet = 'UTF-8';
$mail->Subject = $subject;
$mail->Body = $body;
As you can see, SMTP server doesn't require authentication and all is working ok. That's all data I have about the mail server. Now, I need to make the same thing but instead of using PHPMailer I want to implement the sending method of Laravel, but I don't have any authentication credential for setting my .env file.
How can I pass the same configuration to my Laravel development? I've tried many combinations but nothing happens. This was the last one:
MAIL_DRIVER=smtp
MAIL_HOST=myhost.dev
MAIL_PORT=25
MAIL_USERNAME=no-reply#host.com
MAIL_PASSWORD=''
MAIL_ENCRYPTION=''
PHPMailer has no idea about Laravel, so you need to pass through the information yourself. Laravel provides the env() global function to retrieve data from the environment, and you would use it like this:
$mail->Host = env('MAIL_HOST');
if (!empty(env('MAIL_USERNAME')) {
$mail->SMTPAuth = true;
$mail->Username = env('MAIL_USERNAME');
$mail->Password = env('MAIL_PASSWORD');
}
and so on, for any other configuration variables you need. I'm not sure exactly what Laravel package defines the env function, but you will need to make sure it's loaded and within scope before calling it.
Not working SMTP_validateEmail on live site using php
https://code.google.com/p/php-smtp-email-validation/
<?php
/**
* Example 1
* Validate a single Email via SMTP
*/
// include SMTP Email Validation Class
require_once('smtp_validateEmail.class.php');
// the email to validate
$email = $_POST['name'];
// an optional sender
$sender = $_POST['name'];
// instantiate the class
$SMTP_Validator = new SMTP_validateEmail();
// turn on debugging if you want to view the SMTP transaction
//$SMTP_Validator->debug = true;
// do the validation
$results = $SMTP_Validator->validate(array($email), $sender);
// send email?
if ($results[$email]) {
echo 1;
} else {
echo 0;
}
enter code here
?>
i am having problem on live site but it works fine in localhost.it shows the print_r($results) in the localhost but shows array(0) result in live.i also find $this->sock value in the class smtp_validateEmail.class function validate(email) value empty in live. how to solve this issue any help will be very thankful.
That "Add your web server ip address to var $nameservers = array(‘192.168.0.1’); and if your web server has Port number then update it here var $port = (Port number); Hope you will get the output by making this changes." Only work if you are sending mail with that script but cant tell if that mail checked is good one or not... I have been testing the code, try all changes, but still cant check other mails outside my domain. I can only make it work on my local and webserver host. Still cant call other servers to check if other mails from outside my domain are valid. Working on it.
Complete downloads are here for others to test : https://code.google.com/p/php-smtp-email-validation/downloads/list
Add your web server ip address to var $nameservers = array(‘192.168.0.1’);
and if your web server has Port number then update it here var $port = (Port number);
Hope you will get the output by making this changes.
For a special case in my application, i need to register a user manually from an ajax request.
So, first i send with ajax all my datas : firstname, lastname, mail, password etc... to my controller.
For now, after that, i just do in my controller :
$firstname = $request->get('firstname');
$lastname = $request->get('lastname');
$mail = $request->get('mail');
$password = $request->get('password');
$userManager = $this->get('fos_user.user_manager');
$user = $userManager->createUser();
$user->setUsername($firstname.$lastname);
$user->setPlainPassword($password);
$user->setEmail($mail);
$user->setFirstname($firstname);
$user->setLastname($lastname);
$userManager->updateUser($user);
But my problem, how can i validate the user before updateUser() ? I need to check manually if this email/username already exist ?
How can i do that with a better way ?
You can check if the email arealdy exists with the findUserByEmail method just before the updateUser :
$user = $this->get('fos_user.user_manager')->findUserByEmail($mail);