2011-08-02 7 views
0

이 코드는 유닉스 공유 호스팅 계정에서 정상적으로 작동하지만 어떻게 파일을 첨부합니까? 내가 삭제 한 호스트 이름, 로그인, passwd 파일 등PHP 코드에 파일 첨부하기

<?php 
require_once "Mail.php"; 

$from = "[email protected]"; 
$to = "to email id"; 
$subject = "this is the message from your domain"; 
$body = "give your message body here"; 
$host = "mail.site.com"; 
$username = "user"; 
$password = "pass123"; 
$headers = array ('From' => $from, 
    'To' => $to, 
    'Subject' => $subject); 
$smtp = Mail::factory('smtp', 
    array ('host' => $host, 
    'auth' => true, 
    'username' => $username, 
    'password' => $password)); 
$mail = $smtp->send($to, $headers, $body); 
if (PEAR::isError($mail)) { echo("" . $mail->getMessage() . ""); 
} else { 
    echo("Message Sent successfully "); 
} 
?> 

답변

0

당신이 보낸 모든 이메일을 얻기 위해 두 클래스를 필요로 모두 PEAR :: 메일 및 PEAR :: Mail_Mime를 포함해야합니다. 예 ...

include_once('Mail.php'); 
include_once('Mail_Mime/mime.php'); 
// include_once('Mail/mime.php'); 

// The code below composes and sends the email 

$message = new Mail_mime(); 
$message->setTXTBody($text); 
$message->addAttachment($path_of_attachment_file); 
$body = $message->get(); 
$extraheaders = array("From"=>$from, "Subject"=>$subject,"Reply-To"=>$visitor_email); 
$headers = $message->headers($extraheaders); 
$mail = Mail::factory("mail"); 
$mail->send($to, $headers, $body); 
+0

PECL 메일 패키지는 끔찍한 PEAR 메일을 사용하지 않습니까? –

+0

위의 코드를 읽었습니까? PEAR :: Mail에서 attachment/mime을 사용하는 방법을 묻습니다. 따라서 PEAR에 대한 PECL과 그 질문과 관련이없는 모든 불필요한 것은 여기서 관련이 없습니다. – toopay

관련 문제