0

メール送信用のコードがいくつかありますが、正しく機能していません。

私のコードはここにあります:

class EmailsController extends AppController
{
    var $name="Email";

    var $uses = NULL;

        public function index()
        {
        App::import('Component', 'Email');
        $path=WWW_ROOT."img";
        $filename="Desert.jpg";
        $email->from = 'pal@gmail.com';
        $email->to='abc@gmail.com';
        $email->subject='test mail';
        $email->template = 'simple_message';
        $email->attachments = array($path.$filename);
        $email->SendAs='html';
        if($email->send())
            {
                $this->session->setFlash("Email Send Successfully");

            }
         else
            {
                $this->session->setFlash("Email is not send");
            }

    }

}

次のようなエラーが表示されます。

Call to undefined method stdClass::send()  
4

2 に答える 2

0

詳細については、http: //book.cakephp.org/2.0/en/core-utility-libraries/email.htmlをご覧ください。

<?php
App::uses('CakeEmail', 'Network/Email');
$email = new CakeEmail( $smtp );
$email->to( 'test@example.com' );
$email->subject(__("Reset Password") );
$email->emailFormat('html');
$email->send($body);
?>

SMTP の場合:

以下のコードを「email.php」ファイルとともに app/Config フォルダーに保存し、smtp の詳細を $smtp 配列に入れます。$smtp 変数を new CakeEmail($smtp) に割り当てます。

<?php
class EmailConfig {

    public $default = array(
        'transport' => 'Mail',
        'from' => 'you@localhost',
        //'charset' => 'utf-8',
        //'headerCharset' => 'utf-8',
    );

    public $smtp = array(
        'transport' => 'Smtp',
        'from' => array('site@localhost' => 'My Site'),
        'host' => 'localhost',
        'port' => 25,
        'timeout' => 30,
        'username' => 'user',
        'password' => 'secret',
        'client' => null,
        'log' => false,
        //'charset' => 'utf-8',
        //'headerCharset' => 'utf-8',
    );

}
?>
于 2013-09-19T11:51:25.370 に答える