0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

FuelPHP mail送信(Gmail)

Posted at

1、Googleのセキュリティ設定をする
2、app/config/email.php にある設定ファイルを下記の通りに編集 (無ければpackageからコピー)

/**
 * Mail driver (mail, smtp, sendmail, noop)
 */
'driver' => 'smtp',   
   /**
    * SMTP settings
    */
    'smtp' => array(
        'host' => 'ssl://smtp.gmail.com',
        'port' => 465,
        'username' => 'googleusername',
        'password' => 'googlepassword',
        'timeout' => 5,  // this can be whatever you want
        'starttls' => true,
    ),
    /**
    * Newline
    */
    'newline' => "\r\n"

3、メールを送るファイルを作成

// インスタンスを生成する
$email = Email::forge();

// 送信者のアドレスを指定する
$email->from('hoge@gmail.com', 'My Name');

// 受信者のアドレスを指定する
$email->to('hoge@gmail.com', 'Johny Squid');

// 表題を指定する
$email->subject('This is the subject');

// 送信者のアドレスを複数指定する場合

// $email->to(array(
//     'example@mail.com',
//     'another@mail.com' => 'With a Name',
// ));

// 本文を指定する。
$email->body('This is my message');

try
{
    $email->send();
}
catch(\EmailValidationFailedException $e)
{
    //バリデーションが失敗したとき
}
catch(\EmailSendingFailedException $e)
{
    //ドライバがメールを送信できなかったとき
}
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?