我有僱員應用程序,用戶可以辭職,活動,新建和轉移。我希望實現的是,當員工的職位從主動(standing_id = 1)更改/編輯時,應該能夠通過電子郵件發送,但不能發送。我在EmployeeController中放置了一個電子郵件功能。以下是我的代碼。當您在Cakephp中編輯字段時發送電子郵件
function _sendNewEmployeeEditMail($id) {
$Employee = $this->Employee->read(null,$id);
$email = new CakeEmail();
$email->from(array('[email protected]' => 'Testing App'));
$email->to(array('[email protected]' => 'Name Surname'));
$email->subject('New Employee');
$email->template('employee_email');
$email->viewVars(compact('Employee'));
$email->emailFormat('html');
$edit_email = true;
$current_status = $this->Employee->field('standing_id');
if($current_status==1) {
$edit_email = false;
if ($email->send()) {
$this->Session->setFlash('Your employee has been submitted.','default',array('class' => 'notification'));
return true;
} else {
$this->Session->setFlash('Your employee has not been submitted.','default',array('class' => 'error'));
return false;
}
}
}
,並在我的編輯存儲功能這裏是我如何嘗試發送電子郵件
public function edit($id = null) {
$this->Employee->id = $id;
if (!$this->Employee->exists()) {
throw new NotFoundException(__('Invalid employee'));
}
if ($this->request->is('post') || $this->request->is('put')) {
if ($this->Employee->save($this->request->data)) {
$this->Session->setFlash(__('The employee has been saved'),'default',array('class' => 'notification'));
$this->_sendNewEmployeeEditMail($this->Employee->getLastInsertID() );
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The employee could not be saved. Please, try again.'),'default',array('class' => 'error'));
}
} else {
$this->request->data = $this->Employee->read(null, $id);
}
$standings = $this->Employee->Standing->find('list');
$this->set(compact('standings'));
你只是準備郵件在'_sendNewEmployeeEditMail'功能,但你永遠不會調用CakeEmail組件的'發送()'方法,所以這是可以預料的郵件永遠不會熄滅。 – Oldskool 2013-03-03 10:38:05
@Oldskool我已經在send()方法中,並且仍然沒有收到任何電子郵件。任何想法可能導致這一點? – 2013-03-03 11:12:53