LoginSignup
92
102

More than 5 years have passed since last update.

PHPでメールを送る

Posted at

日本語対応でメールを送るなら、下記のようにすれば良い。

<?php

mb_language("Japanese");
mb_internal_encoding("UTF-8");

$to      = 'to@hoge.co.jp';
$subject = 'タイトル';
$message = '本文';
$headers = 'From: from@hoge.co.jp' . "\r\n";

mb_send_mail($to, $subject, $message, $headers);

日本語対応の必要がなければ下記でOK!

<?php

$to      = 'to@hoge.co.jp';
$subject = 'title';
$message = 'body';
$headers = 'From: from@hoge.co.jp' . "\r\n";

mail($to, $subject, $message, $headers);

ToやCcを複数に送りたい場合は下記参照。

<?php

$to      = 'asdf@hoge.co.jp' . ', ';
$to      .= 'ghjk@hoge.co.jp'
$subject = 'title';
$message = 'body';
$headers = 'From: from@hoge.co.jp' . "\r\n";
$headers .= 'Cc: qwer@hoge.co.jp' . "\r\n";
$headers .= 'Cc: tyui@hoge.co.jp' . "\r\n";

mail($to, $subject, $message, $headers);

(参考URL)
▼mb_send_mail:エンコード変換を行ってメールを送信する
http://php.net/manual/ja/function.mb-send-mail.php
▼mail:メールを送信する
http://php.net/manual/ja/function.mail.php

92
102
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
92
102