2013-06-13 2 views
1

은 이미 서버에있는 .dox .docx .pdf .jpeg의 첨부 파일 두 개를 첨부하여 메일을 보낼 수있는 코드로 링크 경로가 저장 될 수 있습니다. 데이터베이스 (MySql)에?첨부 파일이있는 이메일을 PHP로 전송하는 방법

에서 : 메커니즘을 위해서

하는

제목 :

메시지 :

오전 그냥 초급 I 첨부

확인란 알고있다 메일을 보내는 법 첨부 파일 http://webcheatsheet.com/PHP/send_email_text_html_attachment.php

또는 서버가 PEAR를 지원하는 경우, 당신은 Mail_Mime와 PEAR 메일을 사용한다, 그것은 다음 훨씬 청소기 솔루션 위의 : 벨로

<?php 
$errors = ''; 
$myemail = '[email protected]' 
if(empty($_POST['name']) || 
    empty($_POST['email']) || 
    empty($_POST['message'])) 
{ 
    $errors .= "\n Error: all fields are required"; 
} 

$name = $_POST['name']; 
$email_address = $_POST['email']; 
$message = $_POST['message']; 

if (!preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i", 
$email_address)) 
{ 
    $errors .= "\n Error: Invalid email address"; 
} 

if(empty($errors)) 
{ 
    $to = $myemail; 
    $email_subject = "New Mail From: $name"; 
    $email_body = "$message"; 

    $headers = "From: $myemail\n"; 
    $headers .= "Reply-To: $email_address"; 

    mail($to,$email_subject,$email_body,$headers); 
    //redirect to the 'thank you' page 
    header('Location: thank-you.html'); 
} 

?> 
+0

mail()을 직접 사용하는 대신 메일 링을 위해 미리 만든 라이브러리를 사용해보십시오. Mailheader-Injection을 사용하면 코드가 악용 될 수 있으며 스팸 전송에 악용 될 수 있습니다. –

답변

0

등의 당신은이 페이지를 확인해야합니다.

<?php 

include 'Mail.php'; 
include 'Mail/mime.php' ; 

$text = 'Text version of email'; 
$html = '<html><body>HTML version of email</body></html>'; 
$file = '/home/richard/example.php'; 
$crlf = "\n"; 
$hdrs = array(
      'From' => '[email protected]', 
      'Subject' => 'Test mime message' 
     ); 

$mime = new Mail_mime(array('eol' => $crlf)); 

$mime->setTXTBody($text); 
$mime->setHTMLBody($html); 
$mime->addAttachment($file, 'text/plain'); 

$body = $mime->get(); 
$hdrs = $mime->headers($hdrs); 

$mail =& Mail::factory('mail'); 
$mail->send('[email protected]', $hdrs, $body); 

?> 
+0

코드에서 mail.php와 mime.php의 내용은 무엇입니까 – madcoder

+0

Mail.php와 Mail/mime.php는 PEAR Mail 및 Mail_Mime 패키지의 일부입니다. 서버가 PEAR를 지원한다면,이 파일들을 스크립트의 폴더에 복사 할 필요가 없습니다. PHP는 그것들을 포함 할 것입니다. – langm

관련 문제