본문 바로가기
PHP
2012.03.13 10:27

Send email with mail()

조회 수 4364 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

+ - Up Down Comment Print
?

단축키

Prev이전 문서

Next다음 문서

+ - Up Down Comment Print

DESCRIPTION
bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )

EXAMPLES
------------ example -------------
mail("nobody@example.com", "the subject", $message,
"From: webmaster@{$_SERVER['SERVER_NAME']}\r\n" .
"Reply-To: webmaster@{$_SERVER['SERVER_NAME']}\r\n" .
"X-Mailer: PHP/" . phpversion());

------------ example -------------
$to = "recipient@example.com";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
if (mail($to, $subject, $body)) {
    echo("<p>Message successfully sent!</p>");
} else {
    echo("<p>Message delivery failed...</p>");
}

------------ example -------------
$to = 'user@example.com';
$subject = 'Test';
$message = 'This is a test.';
// set headers as per your requirements.
$headers = 'From: webmaster@nixcraft.co.in' . "\r\n" .
    'Reply-To: webmaster@nixcraft.co.in' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();
 
if ( mail($to, $subject, $message, $headers) ) {
echo 'Message sent!';
} else {
echo 'Message failed, contact webmaster for more info!';
}

------------ example -------------
$to      = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
    'Reply-To: webmaster@example.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

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

------------ example -------------
// multiple recipients
$to  = 'aidan@example.com' . ', '; // note the comma
$to .= 'wez@example.com';

// subject
$subject = 'Birthday Reminders for August';

// message
$message = '
<html>
<head>
  <title>Birthday Reminders for August</title>
</head>
<body>
  <p>Here are the birthdays upcoming in August!</p>
  <table>
    <tr>
      <th>Person</th><th>Day</th><th>Month</th><th>Year</th>
    </tr>
    <tr>
      <td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
    </tr>
    <tr>
      <td>Sally</td><td>17th</td><td>August</td><td>1973</td>
    </tr>
  </table>
</body>
</html>
';

// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
$headers .= 'To: Mary <mary@example.com>, Kelly <kelly@example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday@example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive@example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck@example.com' . "\r\n";

// Mail it
mail($to, $subject, $message, $headers);


Title
List of Articles
번호 분류 제목 글쓴이 날짜 조회 수
36 PHP What does PHP keyword 'var' do? Hojung 2013.12.04 4231
35 MySQL How to reset MySQL’s root password on Mac OS X Hojung 2013.04.24 5519
34 PHP easy way would it be to use str_replace() on the whole file (파일내용변경) Hojung 2012.12.12 5842
33 MySQL Mysql SELECT inside UPDATE Hojung 2012.03.28 5661
32 PHP PHP-MySQLi-Wrapper Hojung 2012.03.28 7049
31 PHP MySQL 연결에서 결과값 얻는 PHP 예 (추천) Hojung 2012.03.28 5059
30 PHP MySQL 주요 PHP 함수 (추천) Hojung 2012.03.28 4661
29 PHP Send email using SMTP server's settings Hojung 2012.03.13 4742
» PHP Send email with mail() Hojung 2012.03.13 4364
27 PHP PHP Upload Progress Bar (APC) Hojung 2012.03.13 5183
26 PHP Rename if exists Hojung 2012.03.12 4482
25 PHP Program execution Functions (exec, system, shell_exec) Hojung 2012.03.11 6298
24 PHP email address validation Hojung 2012.03.11 4212
23 PHP file put contents Hojung 2012.03.01 4746
22 PHP The MVC Design Pattern for PHP Hojung 2012.02.14 6188
21 PHP PHP XML 파서 Hojung 2012.02.02 7238
20 MySQL 모든 호스트의 MySQL 액세스 Hojung 2012.01.27 5266
19 MySQL How Do I Enable Remote Access To MySQL Database Server? Hojung 2012.01.27 5989
18 MySQL 특정게시판의 메일리스트 정보 업데이트 Hojung 2011.12.15 6351
17 MySQL Xpressengine 정회원 메일주소만 Hojung 2011.12.15 6591
Board Pagination ‹ Prev 1 2 Next ›
/ 2

Designed by sketchbooks.co.kr / sketchbook5 board skin

나눔글꼴 설치 안내


이 PC에는 나눔글꼴이 설치되어 있지 않습니다.

이 사이트를 나눔글꼴로 보기 위해서는
나눔글꼴을 설치해야 합니다.

설치 취소

Sketchbook5, 스케치북5

Sketchbook5, 스케치북5

Sketchbook5, 스케치북5

Sketchbook5, 스케치북5