Reputation:
I write a function for registration, after registration I want to send a email from administrator mail address. How can I will set administrator email address in a variable?
this is my function:
function registration() {
$this->loadModel('User');
$this->loadModel('Role');
if ($this->request->is('post')) {
$this->User->set($this->request->data);
if ($this->User->validates()) {
$mail_data = $this->User->save($this->request->data);
$owneremail = $this->request->data['[email protected]'];
$from = $owneremail;
$subject = "Technician registration";
$user_name = $mail_data['User']['name'];
$email_user = $mail_data['User']['email'];
$password = $this->request->data['User']['password'];
$to = array($mail_data['User']['email']);
$mail_content = __('Name:', 'beopen') . $user_name . PHP_EOL .
__('Email:', 'beopen') . $email_user . PHP_EOL .
__('Password:', 'beopen') . $password . PHP_EOL .
__($url = Router::url(array("controller" => "users", "action" => "login"), true));
sendEmail($from, $user_name, $to, $subject, $mail_content);
$msg = '<div class="alert alert-success">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong> User Created succeesfully </strong>
</div>';
} else {
$msg = $this->generateError($this->User->validationErrors);
}
$this->Session->setFlash($msg);
// return $this->redirect('create');
}
$this->set('roles', $this->Role->find("list"));
}
By this code I can't send email from administrator mail address
Upvotes: 3
Views: 128
Reputation: 3074
print the array : $this->request->data
. I think there is no index like [email protected]
It seems you try to set an email in from
attribute. So just assign email to $from. Try this:
step1: remove $owneremail = $this->request->data['[email protected]'];
line
step2: change $from = $owneremail;
to
$from = '[email protected]';
N.B: Study on basic of array and set real email to test email function.
Upvotes: 1