Created
July 17, 2013 13:25
-
-
Save francisrod01/6020537 to your computer and use it in GitHub Desktop.
EmailComponent for CakePHP 2.3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
O bug apresentado é esse: | |
Error: Call to a member function sendmail() on a non-object |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Config/email.php | |
/** | |
* Class EmailConfig | |
* | |
* @example http://book.cakephp.org/2.0/en/core-utility-libraries/email.html | |
*/ | |
class EmailConfig { | |
public $default = array( | |
'transport' => 'Mail', | |
'from' => 'you@localhost', | |
//'charset' => 'utf-8', | |
//'headerCharset' => 'utf-8', | |
); | |
public $smtp = array( | |
'transport' => 'Smtp', | |
'from' => array('EMAIL_AQUI' => 'NOME_SITE'), | |
'host' => 'ssl://hw92.webservidor.net', | |
'port' => 465, | |
'timeout' => 30, | |
'username' => 'EMAIL_AQUI', | |
'password' => 'SENHA_AQUI', | |
'client' => null, | |
'log' => false, | |
//'charset' => 'utf-8', | |
//'headerCharset' => 'utf-8', | |
); | |
public $fast = array( | |
'from' => 'you@localhost', | |
'sender' => null, | |
'to' => null, | |
'cc' => null, | |
'bcc' => null, | |
'replyTo' => null, | |
'readReceipt' => null, | |
'returnPath' => null, | |
'messageId' => true, | |
'subject' => null, | |
'message' => null, | |
'headers' => null, | |
'viewRender' => null, | |
'template' => false, | |
'layout' => false, | |
'viewVars' => null, | |
'attachments' => null, | |
'emailFormat' => null, | |
'transport' => 'Smtp', | |
'host' => 'localhost', | |
'port' => 25, | |
'timeout' => 30, | |
'username' => 'user', | |
'password' => 'secret', | |
'client' => null, | |
'log' => true, | |
//'charset' => 'utf-8', | |
//'headerCharset' => 'utf-8', | |
); | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Controlles/Component/MailSenderComponent.php | |
App::uses('CakeEmail', 'Network/Email'); | |
Class MailSenderComponent extends Component { | |
public function sendmail($subject, $titleMail, $name, $email, $message) { | |
$Email = new CakeEmail(); | |
$Email->config('smtp'); | |
// template use View/Emails/html/contact.ctp AND View/Layouts/Emails/html/simple_contact | |
$Email->template('contact', 'simple_mail') | |
->emailFormat('html') | |
->addHeaders(array('Date' => microtime(true))) | |
->subject($subject) | |
->to(array($email => $name)) | |
->message($message) | |
->send(); | |
return $Email->smtpError ? false : true; | |
} | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Controllers/ProfileController.php | |
... | |
if ($this->MailSender->sendmail($subject, $titleMail, $name, $email, $message)) { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment