2013-12-17 4 views
0

PHP를 사용하여 사진과 CSS 스타일 시트가 포함 된 전자 메일로 HTML 페이지를 보내려고합니다. 어떻게 서버에 이미지를 업로드하지 않고 내 이미지와 CSS 스타일 시트를 추가 할 수 있습니까?PHP를 통해 이메일에 HTML 페이지 보내기

<?php 
$to = "[email protected]"; 

// subject 
$subject = "Test mail"; 

// message 
$message = file_get_contents("index.html"); // index.html contains images and css stylesheet which are not displayin in the email 

// from 
$from = "[email protected]"; 

// 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 .= "From:" . $from; 

// Mail it 
mail($to,$subject,$message,$headers); 

echo "Mail Sent."; 
?> 

내가 크게 도움을 주셔서 감사합니다 :

다음은 sendind 이메일에 대한 PHP 코드입니다. 미리 감사드립니다.

+0

정말 원하는대로 작동하지 않을 것이라고 생각합니다. 대부분의 이메일 클라이언트는 원하는대로 이메일을 표시하지 않습니다. – putvande

+0

이미지가 서버에없는 경우 어떻게 참조 할 수 있습니까? 이미지는 서버에 있어야합니다. –

+0

이미지에 절대 경로 사용 및 적용시 인라인 스타일을 지정해야합니다. CSS는 이메일에서 지원되지 않습니다. – Anup

답변

0

복잡한 이메일 전송의 경우 멋진 PHPMailer 클래스와 같은 메일러 클래스를 사용해야합니다.

이 클래스를 사용하면 HTML 메일과 같은 복잡한 메일을 보내는 것이 매우 쉽습니다. 예제는 PHPMailer의 examples 폴더에 있습니다.

+0

OP는 이미지를 참조하는 것이지 HTML 이메일을 게시하는 방법이 아닙니다. –

+0

'HTML 페이지를 보내려고합니다.'- 사진이 포함 된 HTML 이메일을 보내려고하는 것처럼 들립니다. PHPMailer는 이것을 수행하는 아주 좋은 방법입니다. –

+0

"서버에 이미지를 업로드하지 않고 이미지와 CSS 스타일 시트를 어떻게 추가 할 수 있습니까?" –

0

이 같은 HTML 파일을 보내 추가 할 수 있습니다

$file_name = basename($file); // Get file name 
$data = file_get_contents($file); // Read file contents 
$file_contents = chunk_split(base64_encode($data)); // Encode file data into base64 
$uid = md5(time()); // Create unique boundary from timestamps 
$headers = array(); 
$headers[] = "MIME-Version: 1.0"; 
$headers[] = "From: {$from_name}<{$mail_from}>"; 
$headers[] = "Reply-To: {$mail_from}"; 
$headers[] = "Content-Type: multipart/mixed; boundary=\"{$uid}\""; 
$headers[] = "This is a multi-part message in MIME format."; 
$headers[] = "--{$uid}"; 
$headers[] = "Content-type:text/plain; charset=iso-8859-1"; // Set message content type 
$headers[] = "Content-Transfer-Encoding: 7bit"; 
$headers[] = $message; // Dump message 
$headers[] = "--{$uid}"; 
$headers[] = "Content-Type: application/octet-stream; name=\"{$file_name}\""; // Set content type and file name 
$headers[] = "Content-Transfer-Encoding: base64"; // Set file encoding base 
$headers[] = "Content-Disposition: attachment; filename=\"{$file_name}\""; // Set file Disposition 
$headers[] = $file_contents; // Dump file 
// Send mail with header information 
if (mail($mail_to, $subject, '', implode("\r\n", $headers))) 
    return true; 
관련 문제