PHP & Others

PHP로 메일 보내기 강좌

페이지 정보

본문

▶▶ 윈도우에서 메일이 안보내 질 경우 아래 sendmail 추천 사이트에서 참고하기 바람.
php스쿨에서 Tip & tech 에서 메일이나 mail 로 검색하기 바람 !!
www.phpschool.com 에서 Tip & tech 에서 SMTP 로 검색 하면 됨 !!!  ▶▶

윈도우에서 메일 서버 설치 하기 ! zonesoft.co.kr:8080/~ddns/site/mailserver/download_program.html 위에 메일 서버를 설치 하고 PHP강좌 게시판에서 mail 로 검색 하시고 해보세요. 메일 잘 갑니다 ^^ php.ini 설정 건들지 말고 하세요..윈도우는 ! 


sendmail 를 설치 한 후에 php.ini 에서 sendmail 경로 설정
sendmail_path = "/usr/sbin/sendmail -t -i"
로 설정 한 후 apache 리 스타트 했다...
반드쉬 따옴표(") 로 싸야 합니다.

아래 처럼 했을 경우 메일이 안보내 집니당...!!!
sendmail_path = /usr/sbin/sendmail
sendmail_path = "/usr/sbin/sendmail"




sendmail1.php
-----------------------------------------------------------------------------
<?php
// mail() 사용하기 테스트

// ★ 받는 사람 멜 주소 변경 !!!
$aaa=mail("받는사람메일주소", "제목 : PHP 메일 보내기", "내용 1 \\n 내용 2 \\n ","sss@korea.com");
//mail("받는사람메일주소", "제목 : PHP 메일 보내기", "내용 1 \\n 내용 2 \\n 내용 3");
echo "ssdsdds";
if(!$aaa)
{
 echo "메일 보내기 실패";
}

?>

-----------------------------------------------------------------------------

HTML 형태로 메일을 보낼려면 아래 처럼 Mime 타입을 설정 햐 줘야 함당..


sendmail2.php
-----------------------------------------------------------------------------
<?
$content="<font color=red> PHP tood 내용<br> 카카카 <br> 메롱 </font>";
$email="받는사람메일주소";
$sub="PHP 는 무엇인가 ?";
// tood@tood.net 가 보내는 사람 메일 주소
$from = "From:tood@tood.net\\nContent-Type: text/html; charset=euc-kr\\n";

mail($email, $sub, $content, $from);


?>
-----------------------------------------------------------------------------


파일 첨부 해서 메일 보내기

sendmail3.php
-----------------------------------------------------------------------------
<?
class mime_mail
 {
 var $parts;
 var $to;
 var $from;
 var $headers;
 var $subject;
 var $body;

  /*
  *    void mime_mail()
  *    class constructor
  */       
 function mime_mail()
  {
  $this->parts = array();
  $this->to =  "";
  $this->from =  "";
  $this->subject =  "";
  $this->body =  "";
  $this->headers =  "";
  }

  /*
  *    void add_attachment(string message, [string name], [string ctype])
  *    Add an attachment to the mail object
  */
 function add_attachment($message, $name =  "", $ctype =  "application/octet-stream")
  {
  $this->parts[] = array (
                          "ctype" => $ctype,
                          "message" => $message,
                          "encode" => $encode,
                          "name" => $name
                          );
  }

/*
 *      void build_message(array part=
 *      Build message parts of an multipart mail
 */
function build_message($part)
 {
 $message = $part[ "message"];
 $message = chunk_split(base64_encode($message));
 $encoding =  "base64";
 return  "Content-Type: ".$part[ "ctype"].
                        ($part[ "name"]? "; name = \\"".$part[ "name"]. "\\"" :  "").
                        "\\nContent-Transfer-Encoding: $encoding\\n\\n$message\\n";
 }

/*
 *      void build_multipart()
 *      Build a multipart mail
 */
function build_multipart()
 {
 $boundary =  "b".md5(uniqid(time()));
 $multipart =  "Content-Type: multipart/mixed; boundary = $boundary\\n\\nThis is a MIME
encoded
message.\\n\\n--$boundary";

 for($i = sizeof($this->parts)-1; $i >= 0; $i--)
    {
    $multipart .=  "\\n".$this->build_message($this->parts[$i]). "--$boundary";
    }
 return $multipart.=  "--\\n";
 }

/*
 *      void send()
 *      Send the mail (last class-function to be called)
 */
function send()
 {
 $mime =  "";
 if (!empty($this->from))
    $mime .=  "From: ".$this->from. "\\n";
 if (!empty($this->headers))
    $mime .= $this->headers. "\\n";
   
 if (!empty($this->body))
    $this->add_attachment($this->body,  "",  "text/plain"); 
 $mime .=  "MIME-Version: 1.0\\n".$this->build_multipart();
 mail($this->to, $this->subject,  "", $mime);
 }
};  // end of class

 // rb 옵션으로 변경  ★ gnome 파일명 변경 요망 !!!
 $attachment = fread(fopen("gnome.gif", "rb"), filesize("gnome.gif"));

 $mail = new mime_mail();
 $mail->from = "tood@tood.net";
 $mail->headers = "Errors-To: tood@tood.net";
 $mail->to = "받는사람메일주소";  // ★ 받는 사람 멜 주소 변경 !!!
 $mail->subject = "파일 첨부 메일 테스트";
 $mail->body = "<font color=blue>tood.net 파일 첨부 테스트 \\n 카카카카 \\n  쿠쿠쿠쿠 메롱
</font>";

// ★ gnome 파일명 변경 요망 !!!
 $mail->add_attachment("$attachment", "gnome.gif", "image/gif");
 $mail->send();
 
?>

-----------------------------------------------------------------------------



참조 숨은 참조로 메일 보내기 PHP4이상에서만 됩니다 ^^

-----------------------------------------------------------------------------

<?
  $target = "to_email_address";
  $subject = "subject_email";
  $text = "email_message";

    // Questa sono le righe che funzionano da
    // intestazione alla mail
    $header = "From: vostra@mail.it
              Reply-To: vostra@mail.it
              X-Mailer: PHP/4.0.2
              bcc: indirizzo@dichivuoi.it, indirizzo2@dichivuoi.it
              cc: indirizzo@veditu.it, indirizzo2@veditu.it";
        // Le ultime due righe mandano la mail in CC o in BCC
    // Funzione mail!
  mail ($target,$subject,$text,$header);

?>
-----------------------------------------------------------------------------

관련자료

등록된 댓글이 없습니다.
Today's proverb
진실의 빛은 자주 가려지기는 하지만 결코 꺼지지는 않는다.