2011-08-02 8 views
0

このコードは、私のUNIX共有ホスティングアカウントで問題なく動作しますが、どのようにファイルを添付しますか? 私が削除したホスト名、ログインは、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 :: Mailと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で添付ファイル/ MIMEを使用する方法を尋ねています。だから、PECLとPEARについて話すことと、その質問と関係のない不必要なことは、ここでは関係ありません。 – toopay