Reputation: 13
I know this kind of question is a typical newbie error, and I am a newbie. I'm confused. Everything seems right. Can anyone please help me and point me out where the syntax error is?
Here is what the Stack Trace said
CORE\Cake\Network\Email\CakeEmail.php line 362 → CakeEmail->config(string)
}
if ($config) {
$this->config($config);
} elseif (config('email') && class_exists($this->_configClass)) {
APP\Controller\ContactsController.php line 141 → CakeEmail->__construct(string)
}
}
$Email = new CakeEmail('smtp');
$Email->template('MassMail');
'smtp'
And here is how my controller for this page looks like:
public function mail() {
$allCity = $this->City->find('all');
$this->set('city', $this->City->find('list'));
$this->set('cityall', $allCity);
if ($this->request->is('post')) {
$to = [];
$subject = $this->request->data['Emails']['judul'];
$content = $this->request->data['Emails']['content'];
$toList = $this->request->data["Emails"]["to"];
foreach ($toList as $kota) {
foreach ($allCity as $cityObj) {
if ($kota == $cityObj['City']['kota']) {
foreach ($cityObj['Contact']as $kontak) {
if ($kontak['email'] != "") {
array_push($to, $kontak['email']);
}
}
}
}
}
$Email = new CakeEmail('smtp'); //--> Line 141
$Email->template('MassMail');
$Email->emailFormat('html');
$Email->viewVars(['content' => $content]);
$Email->from(['[email protected]' => 'Forkom Jerman']);
$Email->to($to);
$Email->subject($subject);
$Email->replyTo('[email protected]');
$Email->transport('smtp');
if ($Email->send()) {
$this->Flash->set('Email Telah terkirim');
} else {
$this->Flash->set('Email tidak bisa terkirim');
};
}
}
And here is my email config:
public $smtp = array(
'log' => true;
'transport' => 'smpt',
'from' => '[email protected]',
'host' => 'send.one.com',
'port' => 465,
'username' => 'forkom.****@gmail.com',
'password' => '*****!',
//'charset' => 'utf-8',
//'headerCharset' => 'utf-8',
);
I have tried changing the smpt to default, or even leaving it blank so it'll automatically use the default ($Email = new CakeEmail();) I even tried to just copy paste the snippets from cookbook directly that looks like this, just to see how it should be.
$Email = new CakeEmail();
$Email->from(array('[email protected]' => 'My Site'));
$Email->to('[email protected]');
$Email->subject('About');
$Email->send('My message');
But the syntax error message still pointing out to : $Email = new CakeEmail();
I've also tried to clear the cache in tmp>cache>presistent>myapp_cake_core_file_map
But still nothing changed.
Any suggestion would be very helpful. Thanks!
Upvotes: 1
Views: 99
Reputation: 25698
First, the paste of your stack trace is almost useless because it doesn't really contain the whole information and is terrible formatted. By looking at the code I spotted this and assume it's the cause:
public $smtp = array(
'log' => true; // <--- Wrong
'transport' => 'smpt',
It's a semicolon in an array declaration. Fix it and see what happens. If the issue still appears please post the whole trace and properly formatted.
Also, is there any particular reason why you start learning CakePHP2? It's pretty outdated these days. Go for CakePHP3, even if it is "just" for learning purposes.
Upvotes: 3