I have the following function being called from my view.ctp file after a form button is pressed. However nothing is being recieved. Any advice?
public function email(){
// ============Email================//
/* SMTP Options */
$this->Email->smtpOptions = array(
'port' => '465',
'timeout' => '30',
'host' => 'ssl://smtp.gmail.com',
'username' => 'email1#gmail.com',
'password' => 'password1',
'transport' => 'Smtp'
);
// sending/receiver details for email
$this->Email->template = 'resetpw';
$this->Email->from = 'Cafe <email1#gmail.com>';
$this->Email->to = 'Andrew <email2#gmail.com';
$this->Email->subject = 'Junto Cafe: Password reset';
$this->Email->sendAs = 'both';
$this->Email->delivery = 'smtp';
$this->set('ms', $ms);
$this->Email->send();
$this->set('smtp_errors', $this->Email->smtpError);
// after sending, display a notification
$this->Session->setFlash(__('Check Your Email To Reset your password', true) , 'alert-box', array(
'class' => 'alert-success'
));
// ============EndEmail=============//
}
Solved. Forgot to add
App::uses('CakeEmail', 'Network/Email');
Related
I got this eror while trying to send email with cakeMail. Although I have following code from the cookbook 1 on 1.
Here are some snippets from my controller:
App::uses('AppController', 'Controller');
App::uses('CakeEmail', 'Network/Email');
...
...
...
public function index() {
....
$Email = new cakeEmail('smtp');
$Email->template('MassMail')
->emailFormat('html')
->viewVars([
'content' => $content
])
->from(['info#forkom-jerman.org' => 'Forkom Jerman'])
->to($to)
->subject($subject)
->replyTo('forkom.jerman#gmail.com')
->transport('smtp');
if ($Email->send()) {
$this->Flash->set('Email Telah terkirim');
} else {
$this->Flash->set('Email tidak bisa terkirim');
}
}
On the email.php on config folder:
class EmailConfig {
public $smtp = array(
'transport' => 'Smtp',
'from' => 'info#forkom-jerman.org',
'host' => 'send.one.com',
'port' => 465,
'username' => '*****#gmail.com',
'password' => '******',
//'charset' => 'utf-8',
//'headerCharset' => 'utf-8',
);
}
Please tell me where it went wrong.
The class to use is CakeEmail instead of cakeEmail.
You need to instantiate it like this:
$Email = new CakeEmail('smtp');
I want to use my email on my server with CakePHP IMAP Custom Datasource.
In database.php I have:-
public $myCustomEmail = array(
'datasource' => 'ImapSource',
'server' => 'test.com',
'username' => 'info#test.com',
'password' => 'email password',
'port' => 143,
'ssl' => true,
'encoding' => 'UTF-8',
'error_handler' => 'php',
'auto_mark_as' => array(
'Seen',
// 'Answered',
// 'Flagged',
// 'Deleted',
// 'Draft',
),
);
When I set port to 143 or ssl to true I get this error:-
Error: Unable to get imap_thread after 4 retries. 'TLS/SSL failure for radindesign.com: SSL negotiation failed'
When ssl is set to false or I change the port I get this error:-
Unable to get imap_thread after 4 retries. 'Certificate failure for test.com: self signed certificate: /CN=linux10.centraldnserver.com/emailAddress=ssl#linux10.centraldnserver.com'
What's wrong with the IMAP authentication?
CakePHP IMAP Custom Datasource didnt help me i use from this :
// Configure your imap mailboxes
$mailboxes = array(
array(
'label' => 'Gmail',
'mailbox' => '{imap.gmail.com:993/imap/ssl}INBOX',
'username' => 'yourusername#gmail.com',
'password' => 'yourpassword'
),
array(
'label' => 'My Cpanel website',
'mailbox' => '{mail.yourdomain.com:143/notls}INBOX',
'username' => 'info+yourdomain.com',
'password' => 'yourpassword'
),
array(
'label' => 'Another mail account',
'mailbox' => '{mail.yourdomain.com:143/notls}INBOX',
'username' => 'info#yourdomain.com',
'password' => 'yourpassword'
)
);
//check inbox
$current_mailbox = array(
'label' => 'My Cpanel website',
'mailbox' => '{mail.test.com:143/notls}INBOX',
'username' => 'info#test.com',
'password' => '***'
);
// Open an IMAP stream to our mailbox
$stream = #imap_open($current_mailbox['mailbox'], $current_mailbox['username'], $current_mailbox['password']);
$emails = imap_search($stream, 'SINCE ' . date('d-M-Y', strtotime("-1 week")));
// If we've got some email IDs, sort them from new to old and show them
rsort($emails);
$i = 0;
$overview = array();
foreach ($emails as $email_id) {
// Fetch the email's overview and show subject, from and date.
$overview[$i] = imap_fetch_overview($stream, $email_id, 0);
$i++;
}
var_dump($overview);
Hello Everyone,
I am trying to send email through cakephp framework,but unfortunately email are not getting delivered. But when i use social email service provider such as google, outlook and rediffmail e-mail gets delivered.
My SMTP port is 465. I am using below cakephp mail()function:
public $gmail = array(
'host' => 'ssl://smtp.techphant.com',
'port' => 465,
'username' => 'xyz#abc.com',
'password' => 'xxxxxx',
'transport' => 'smtp',
);
Also i have tried port number 2525 and 25 but to no avail.
Please let me know your suggestions.
Thanks in advance.
Try to send eamil with cake Email component not with mail() function.
$this->set(
'content',
'<h1>Hi </h1>
<p>Thanks for contact us. We will respond you soon</p>
'
);
$this->Email->smtpOptions = array(
'host' => 'ssl://smtp.techphant.com',
'port' => 465,
'username' => 'xyz#abc.com',
'password' => 'xxxxxx',
'timeout' => 30,
'client' => null
);
$this->Email->to = 'abc#gmail.com';
$this->Email->subject = 'Thanks for contact us';
$this->Email->from = 'no_reply#abc.com';
$this->Email->template = 'default';
$this->Email->sendAs = 'html';
$this->Email->send();
Thanks..!
I am newbie to cake php and I have a problem.
When a user updates his profile iam asking to enter his password.Now I dont know how to check it with the stored password.
<?php echo $form->create('UserProfile', array('url' => array('action' => 'edit_profile', 'controller' => 'users'))); ?>
<?php
echo $form->input('nickname', array('label' => __('Display Name', true), 'class' => 'INPUT required'));
?>
<b>To save these settings, please enter your password</b><br /><br />
<?php
echo $form->input('repeat_password', array('label' => __('Password', true), 'class' => 'INPUT required','type'=>'password'));
echo $form->input('private', array('label' => __('Set Profile Private', true), 'class' => 'INPUT required'));
?>
<!-- <div id="CityList">
<?php
// echo $form->input('city', array('id' => 'citySelect', 'name' => 'data[UserProfile][city]', 'empty' => __('Please select city', true), 'label' => __('City', true), 'class' => 'INPUT required'));
?>
</div> -->
<?php echo $form->submit(__('Submit', true), array('class' => 'save_btn')) ?>`
>
In My model i have applied the following validation on repeat password.
'repeat_password' => array(
array('rule' => 'check_repeatPassword'),
array('rule' => 'notempty', 'message' => __('Required', true), 'require' => true),
array('rule' => 'alphaNumeric', 'allowEmpty' => true, 'message' => __('Password must only contain letters and numbers.', true)),
array('rule' => array('minLength', 6), 'allowEmpty' => true,
'message' => __('Password must be at least 6 characters long.', true)),
array('rule' => array('maxLength', 16), 'allowEmpty' => true,
'message' => __('Password must be at most 16 characters long.', true))
),
function check_repeatPassword($data) {
$repeatPassword = $data['repeat_passowrd'];
$passwordExists = $this->find('count', array('conditions' => array('User.repeat_password' => $repeatPassword)));
if ($passwordExists == 0) {
return false;
}
return true;
}
In My Controller I have made the following edit profile method.
function edit_profile() {
$this->loadModel('UserProfile');
$user = $this->_authenticate_user();
$id = $user['account_num'];
if (!empty($this->data)) {
$this->data['UserProfile']['account_name'] = $id;
unset($this->data['UserProfile']['country']);
unset($this->data['UserProfile']['city']);
if ($this->UserProfile->save($this->data)) {
$userInfo = $this->User->getUserInfo($id);
$this->User->reassign_session($userInfo);
$this->flashMessage(__('Your Profile has been Updated successfully', true), 'Sucmessage');
//$this->redirect(array('action' => 'profile'));
} else {
$this->flashMessage(__('Your Profile has not been updated. Please, try again.', true));
}
}
if (empty($this->data)) {
$this->data = $this->UserProfile->read(null, $id);
}
// $this->loadModel('Country');
// $countries = $this->Country->find('list');
// $this->set('countries', $countries);
$this->loadModel('Nationality');
$nationalities = $this->Nationality->find('list', array('fields' => array('name', 'name')));
$this->set('nationalities', $nationalities);
$this->pageTitle = __('Edit My Profile', true);
}
Kindly help me how to do this.Thankssssss in advance
You are not storing passwords in plain text
I cannot avoid seeing this and being amazed:
$passwordExists = $this->find('count', array(
'conditions' => array(
'User.repeat_password' => $repeatPassword
)
));
Please, please confirm that you aren't storing user passwords in plain text, and if you are stop doing so immediately and execute the following sql:
ALTER TABLE users DROP repeat_password;
Compare a hash with a hash
In the db, you should have the user's existing password stored as a one-way-hash. Assuming that's the case, to verify that the user entered their existing account password - just hash what they provided in the same way the Auth component does, and compare to the db:
function check_repeatPassword($data) {
$userId = $this->data['UserProfile']['account_name']; // from the question
$userInput = current($data);
$hashedUserInput = Security::hash($userInput, null, true);
return $this->find('count', array(
'conditions' => array(
'password' => $hashedUserInput,
'id' => $userId
)
));
}
This will confirm that the password the user entered, is the same as the one already in the db for that user.
This is a fairly long question but I have know idea where it's going wrong. I am making an ajax login script using CakePHP 2.0 but it keeps failing. I will post all of my code, and i hope someone has the time to go through it.
This is my sql Database
AccountID AccountEmail AccountPassword AccountActive
1 chris#hotmail.co.uk pass 0
2 chris#gmail.com pass 1
This is my relevant Model Code
class Account extends AppModel {
public $name = 'Account';
public $validate = array(
'AccountEmail' => array(
'required' => array(
'rule' => array('notEmpty'),
'message' => 'Please Enter A Valid Email.'
),
'email' => array(
'rule' => array('email', true),
'message' => 'Please supply a valid email address.'
)
),
'AccountPassword' => array(
'required' => array(
'rule' => array('notEmpty'),
'message' => 'Please Enter A Valid Password.'
)
)
);
}
This is my relevant Controller Code
class AppController extends Controller {
/**
* Class Variables
*/
public $helpers = array('Js', 'Html', 'Session', 'Form');
public $components = array(
'Session',
'RequestHandler',
'Auth' => array(
'logoutRedirect' => array(
'controller' => 'Accounts',
'action' => 'login'
),
'authError' => 'You can\'t Access That Page',
'authorize' => array('Controller'),
'authenticate' => array(
'Form' => array(
'fields' => array(
'username' => 'AccountEmail',
'password' => 'AccountPassword'
),
'scope' => array('AccountActive' => '1')
)
)
)
);
}
class AccountsController extends AppController {
/**
* Class Variables
*/
public $name = 'Accounts';
public $layout = 'Accounts';
/**
* Class Functions
*/
public function login()
{
if ($this->request->is('ajax')) {
$this->Account->set($this->data);
if ($this->Account->validates()) {
if($this->Auth->login()) {
echo "logged In";
exit;
} else {
echo "Login Failed";
exit;
}
} else {
echo 'validation/' . json_encode($this->Account->invalidFields());
exit;
}
}
}
I don't think there is anything else. Again i'm sorry for the huge amount of code but i just don't know what you need.
The info is all passed via 'echo' to jquery which at the moment is just displaying the response via 'alert'.
I know the validation is working, but if i enter the info of someone who should be able to login it just shows "Login Failed". Thanks For Your Time.
Your passwords in the database need to be in their hashed form. Using Cake's default settings, 'pass' would be: 1c31af5bd9913ff511fe780f506e6fab68979b90