본문 바로가기
PHP
2012.03.13 10:27

Send email with mail()

조회 수 3795 추천 수 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 3486
35 MySQL How to reset MySQL’s root password on Mac OS X Hojung 2013.04.24 4837
34 PHP easy way would it be to use str_replace() on the whole file (파일내용변경) Hojung 2012.12.12 5142
33 MySQL Mysql SELECT inside UPDATE Hojung 2012.03.28 4986
32 PHP PHP-MySQLi-Wrapper Hojung 2012.03.28 6308
31 PHP MySQL 연결에서 결과값 얻는 PHP 예 (추천) Hojung 2012.03.28 4497
30 PHP MySQL 주요 PHP 함수 (추천) Hojung 2012.03.28 4097
29 PHP Send email using SMTP server's settings Hojung 2012.03.13 4180
» PHP Send email with mail() Hojung 2012.03.13 3795
27 PHP PHP Upload Progress Bar (APC) Hojung 2012.03.13 4553
26 PHP Rename if exists Hojung 2012.03.12 3918
25 PHP Program execution Functions (exec, system, shell_exec) Hojung 2012.03.11 5624
24 PHP email address validation Hojung 2012.03.11 3664
23 PHP file put contents Hojung 2012.03.01 4206
22 PHP The MVC Design Pattern for PHP Hojung 2012.02.14 5527
21 PHP PHP XML 파서 Hojung 2012.02.02 6559
20 MySQL 모든 호스트의 MySQL 액세스 Hojung 2012.01.27 4715
19 MySQL How Do I Enable Remote Access To MySQL Database Server? Hojung 2012.01.27 5384
18 MySQL 특정게시판의 메일리스트 정보 업데이트 Hojung 2011.12.15 5729
17 MySQL Xpressengine 정회원 메일주소만 Hojung 2011.12.15 5924
Board Pagination ‹ Prev 1 2 Next ›
/ 2

Designed by sketchbooks.co.kr / sketchbook5 board skin

나눔글꼴 설치 안내


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

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

설치 취소

Sketchbook5, 스케치북5

Sketchbook5, 스케치북5

Sketchbook5, 스케치북5

Sketchbook5, 스케치북5