I'm sending an email using CakePHP and I got an Error: SMTP server did not accept the password, along with an email in my inbox says that: sign-in attempt blocked! , we recently blocked a sign-in attempt to your Google Account.
Is that normal?
I'm using Xampp.
function sendActivationEmail($user_id)
{
Debugger::dump($user_id);
$user = $this->User->findById($user_id);
if ($user==false)
{
debug(__METHOD__." failed to retrieve User data for user.id: {$user_id}");
return false;
}
$this->set('username', $this->data['User']['username']);
$this->Email->to = $user['User']['email'];
$this->Email->subject = env('SERVER_NAME').'- Please confirm your email address';
$this->Email->from = 'laurent#gmail.com';
$this->Email->template = 'account_verification';
$this->Email->delivery = 'smtp';
$this->Email->smtpOptions = array(
'port'=>'465',
'timeout'=>'30',
'host' => 'ssl://smtp.gmail.com',
'username'=>'laurent#gmail.com',
'password'=>1234567
);
$this->Email->sendAs = 'text';
return $this->Email->send();
}
You need to allow "less secure" apps in your Google account settings:
https://www.google.com/settings/security/lesssecureapps
See this announcement as well http://googleonlinesecurity.blogspot.de/2014/04/new-security-measures-will-affect-older.html
You should implement OAuth2 instead of weakening the security!
Make sure that the field in 'username' => and 'password'=> is authenticate or valid. I had experienced the same issue and all I do is to go this link https://accounts.google.com/b/0/DisplayUnlockCaptcha and click the button 'Continue'.
make sure you're logged in in gmail using the 'username' and 'password' provided in your code. After that, try to send email again.
I was facing same issue. in my case Password was not so strong. It contains username in password. I change the password and try again. it works.
*The other thing you can do that you can use other email address with strong password. make sure captcha is and less secure is enabled. *
https://accounts.google.com/b/0/DisplayUnlockCaptcha
Related
i am trying to sending mail using cakephp 3.0 .
My code is :
Email::configTransport('WebMail',[
'className' => 'Smtp',
'host' => $host,
'port' => $port,
'timeout' => 30,
'username' => $username,
'password' => $password,
'client' => null,
'tls' => null]
);
$transport = ['transport' => 'WebMail'];
$email = new Email($transport);
$email
->from([$username => $senderName])
->to($email_to)
->subject('Password Reset Code');
$response = $email->send('hello');
its working fine but the problem is how to check if the email was delivered successfully or not to the recipient.
if I debug $response variable I got the array of all mail related data.
Now how can I check if the email was delivered or not .
You can't... at least not reliably. All CakePHP can tell you is whether sending/queing the mail was successful, and depending on the transport (Smtp/Mail/...) that you're using you can get the last response received from the E-Mail server.
If sending/queing was unsuccessful, a \Cake\Network\Exception\SocketException exception will be thrown, so catch that if you want to evaluate this problem. Other than that there's no further information CakePHP/PHP can provide you with.
try {
$email->send();
} catch (\Cake\Network\Exception\SocketException $exception) {
// sending/queing failed
// the last response is available when using the Smtp transport
$lastResponse = $email->transport()->getLastResponse();
}
If applicable you could use a custom Smtp transport and implement requesting DSNs (Delivery status notifications, which you could then evaluate later on, however this isn't foolproof either, as notifications aren't guaranteed.
See also
API > \Cake\Mailer\Transport\SmtpTransport::getLastResponse()
API > \Cake\Mailer\Email::transport()
You'll need to add some form of tracking pixel to the email, or just use a transactional email service like Mandrill (MailChimp) or SendGrid...etc that will do this for you. You can then see whether they received it, and if they opened it...etc.
You can manually open the inbox of sending email to check if the mail was sent. If due to any reason the mail could not be sent, you'll receive a revert mail stating the problem.
Now, I know this is not a very efficient method so you need to keep these things in mind :-
1. You need to lower the security of your email.
2. You should not send codes (JavaScript etc) on email.
3. Keep in mind the size of content you are sending.
With these points checked you can assume your mail was sent. For a safer side you can check you mail once a week/month to see if all the mails were sent or if you got any error.
I created a CRUD that allows me to create users, societies and schools in a back office.
However, for an unknown reason, I can't log in with a created user with the password I gave him.
Here is my controller (the part where the user is created)
/**
* Creates a new User entity.
*
* #Route("/new", name="user_new")
* #Method({"GET", "POST"})
*/
public function newAction(Request $request)
{
$user = new User();
$form = $this->createForm('UserBundle\Form\UserType', $user);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrine()->getManager();
$password = $this->get('security.password_encoder')->encodePassword($user, $user->getPassword());
$user->setPassword($password);
$em->persist($user);
$em->flush();
return $this->redirectToRoute('user_show', array('id' => $user->getId()));
}
return $this->render('user/new.html.twig', array(
'user' => $user,
'form' => $form->createView(),
));
}
After registering a new user, when I check it in the fos_user table, I can see that the password has been encrypted. However, if I try to login with the password I used, I simply get "bad credential" from my login form.
I can't figure out why.
Tell me if you need to see another file, I'll update my question
Any idea ?
Thank you in advance
The correct way to create user and set password in FOSUserBundle is the following:
$userManager = $this->container->get('fos_user.user_manager');
$userAdmin = $userManager->createUser();
$userAdmin->setUsername('System');
$userAdmin->setEmail('system#example.com');
$userAdmin->setPlainPassword('test');
$userAdmin->setEnabled(true);
$userManager->updateUser($userAdmin, true);
Password is kept encrypted in database. And to make it harder to bruteforce, database contains an additional field, named salt. You don't store it in your code, that's why it's impossible later to check password. But actually, you don't have to encrypt password and store it in database. User model contains a special method for it, setPlainPassword, which is intended to encrypt password populate both fields salt and password in database with correct values.
I am having problem on sending email via cake php 2.7. Well, the email gets forwarded to the desired email address but there is problem in getting sender email address, as I am getting configuration email address in the place of sender email address. I have problem in getting how to fix this issue. It would be grateful if anybody could suggest anything regarding the issue.
Some parts of code are:
pages controller
public function sendEmail($data) {
$email = new CakeEmail();
$email->config('gmail');
$email->emailFormat('html');
$email->sender($data['User']['email_address'],$data['User']['name']);
$email->from(array($data['User']['email_address'] => $data['User']['name']));
$email->to('configuration_email');
$email->replyTo($data['User']['email_address']);
$email->subject($data['User']['subject']);
$message = 'Name: '.$data['User']['name'].'<br> How Did You Hear: '. $data['User']['how_did_you_hear'].
'<br>Message: '.$data['User']['body'];
if ($email->send($message))
{
return true;
}else {
return false;
}
}
email.php
public $gmail = array(
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'username' => 'configuration_email',
'password' => 'password',
'transport' => 'Smtp'
);
'From' field is using configuration email instead of using $data['User']['email'].
Thank you in advance!
Gmail lets you send messages on behalf of an email address different from your Gmail address only if you already own that email account and it is properly registered in your Gmail account.
Instructions are described in Gmail: Send mail from a different address or alias:
I'm a Gmail or Google Apps user sending from an external address.
Click the gear in the top right .
Select Settings.
Click the Accounts and Import tab.
Under Send mail as, click Add another email address.
In the 'Email address' field, enter your name and alternate email address you own.
Enter the SMTP server (e.g. smtp.domain.com), your username on that domain, and your password for that account. You may also need to adjust your port setting or SSL setting (talk to your other ISP if you need this information).
Click Add account >>
Open your other account and either click the link in the message Gmail sent or enter the confirmation code in the Accounts and Import section of your Gmail settings.
If Gmail sent a verification email and you didn’t receive it, try checking your Spam or Bulk Mail folders for a message from account-verification-noreply#google.com to see if the email ended up in there.
I am using cakephp, and sending email through cakeemail with smtp. My hosting is on 1and1.com. Email is going to deliver on gmail but not on yahoo and hotmail.
Then I try the PHPMailer on same server and its email was going to deliver on gmail and hotmail as well. But unfortunatly I am unable to use PHPMailer with cakephp. I have try two tutorial but fails. One of them is here.
I will prefer to fix the problem with cakeemail, if some one can help regarding this.
Or if can get solution with PHPMailer for cakephp that is also ok.
Here is the my code
$email = new CakeEmail();
$email->smtp = array(
'port'=>'25',
'timeout'=>'30',
'host' => 'smtp.1and1.com',
'username'=>'quote#xxxxxx.com',
'password'=>'xxxxxx_',
'client' => 'smtp.1and1.com' ,
'transport' => 'Smtp'
);
$email->from(array('xxxx#a-xxxx.com' => 'A-Best Auto Parts Quote'));
$email->to("xxxx#yyy.com");
//$email->bcc("xxxx#yyy.com");
$email->subject('My Test Subject');
$email->emailFormat('html');
$body="the test message for email"
$email->send($body);
I'm trying to find a way to log in user without password.
The reason is that I have phpBB3 forums in my site and the users already log in there. So I'm now building an expansion to the site to have more than just the forum (Using CakePHP). I thought that I could attach automatic account creation to CakePHP when user creates an account to forums (And ofcourse other link for the existing users). So the users would get CakePHP account that has the same username that they have registered in forums. That means that the only way to register to CakePHP part of the site would be to register to the forums first.
Now I'd like to handle the whole logging thing by phpBB3 login so users would still login to forums, and then I'd attach a piece of code that would also login them to CakePHP part of the site with the username they used to login to forums.
This way I could do also put users to their own ACL groups by their status in forums.
Thats what I'm after and I need to know the way to login users this way. I'm not looking for complete code I'm just looking for an answer that explains how I log in users in CakePHP without them having passwords at all.
I have also looked http://bakery.cakephp.org/articles/wilsonsheldon/2009/01/13/phpbb3-api-bridge but it just doesn't quite look what I'm looking for...
As far as I recall, Auth requires two pieces of info for a login.
You can change which fields in the users table are checked by auth with.
$Auth->fields = array(
'username' => 'username',
'password' => 'password'
);
So if you you want to be able to log in users according to their nickname and shoesize:
$Auth->fields = array(
'username' => 'nickname',
'password' => 'shoesize'
);
IMPORTANT:
The AuthComponent expects the password value stored in the database to be hashed instead of being stored in plaintext.
(I think it is a sha1 of the password and Security.salt)
In the above example, if any entries already existed in the database you'd have to overwrite the shoesize field for each of them with hashed versions of the shoesizes.
To generate a hashed password yourself you can use $Auth->password('A Password');
Quick and Dirty
If you fill the password fields in your users table with the return value of:
$Auth->password(null);
Then you can use the following:
$Auth->login(
array(
'User'=>array(
'username'=> USERNAME_FROM_PHPBB3,
'password'=>null
)
)
);
Less Quick and Dirty
When creating a new user.
Set the password field to the md5 hash of some random input.
$this->authUser[$this->User->alias][$Auth->fields['password']] = $Auth->password(md5(rand().rand()));
Use the Username from phpBB3 to retrieve the relevant record
from the users table in the database.
$this->authUser = $this->User->findByUsername( USERNAME_FROM_PHPBB3 );
If the query was successful Log in the user
if($this->authUser){
if($Auth->login($this->authUser)){
// Login Successful
}
}
From your cakephp app you can check if a user exist in the phpbb forums table and you can use the phpbb session to check if a user is logged in.
This function will solve your problem:
public function forceLogin($userName = NULL) {
$this->_setDefaults();
$this->User = ClassRegistry::init('User');
$this->User->recursive = 0;
$user = $this->User->findByUsername($userName);
if (!empty($user['User'])) {
$this->Session->renew();
$user['User']['id'] = null;
$user['User']['password'] = null;
$this->Session->write(self::$sessionKey, $user['User']);
}
return $this->loggedIn();
}