2014-12-19 1 views
-2

오케이, 이건 까다 롭습니다. (나는 생각한다). 메시지를 받았을 때 이메일의 상단 또는 하단에 이미지가있는 것을 알고 있습니까? 나는 그것을 만들기 위해 노력했지만 그것을 알아낼 수 없습니다. 당신이이 문제에 대해 저를 도울 수 있기를 바랍니다.전자 메일 메시지에 이미지를 붙여 넣으려면 어떻게합니까?

이것은 내가 지금까지 얻은 것입니다.

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

    if(isset($_POST['submit'])) 
    { 

    $name = $_POST['name']; 
    $gast = $_POST['email']; 
    $tmpName = $_FILES['attachment']['tmp_name']; 
    $fileType = $_FILES['attachment']['type']; 
    $fileName = $_FILES['attachment']['name']; 



    if(empty($errors)) 
    { 

    $to = $to; 
    $from = $gast; 
    $file = fopen($tmpName,'rb'); 
    $data = fread($file,filesize($tmpName)); 
    fclose($file); 

    $mimeBoundary = "==Multipart_Boundary_x{$randomVal}x"; 

    $body = "E-mail". 
    "Name: $name\n". 
    "Email: $gast \n". 
    "Content-Type: {$fileType};\n". 
    "Content-Transfer-Encoding: base64\n\n". 
    $data; 

    $headers = "From: $from \r\n"; 
    $headers .= "Email: $gast \r\n"; 
    $headers .= "\nMIME-Version: 1.0\n"; 
    $headers .= "Content-Type: multipart/alternative;\n"; 
    $headers .= " boundary=\"{$mimeBoundary}\""; 
    $headers .= "img src='http://cache.estivant.nl/image/1399025430_12_banners-bestemmingen-single-1680x460-extra2-06-kos_1399025430.jpg' alt='image'"; 

    $data = chunk_split(base64_encode($data)); 

    mail($to, $body, $headers); 

    } 
    } 

    ?> 


    <html> 
    <head></head> 
    <body> 
    <form method="post" action=""> 

    <label for="name">name</label> 
    <input type="name" name="name" value="" /> 

    <label for="email">email</label> 
    <input type="email" name="email" value="" /> 

    <button id="submit" name="submit">send</button> 
    </form> 
    </body> 
    </html> 

답변

0

css 스타일로 html 페이지를 작성하고 이에 따라 이메일을 형식화하고 이메일 본문으로 html을 사용하십시오. 이

<img src="image.jpg" alt="image"></img> 

당신이 그들의 신뢰 발신자 목록 또는 연락처에없는대로 (모든 경우) 대부분의 이메일 클라이언트가 한 수신기에 보여지는 이미지를 차단 점에 유의하십시오 우편으로 이미지를 만듭니다 명부. 물론

, 이메일은 이미지와 잘 포맷 된 이메일의 예는 HTML 여기

0

같다 확인할 수있다.

참고 이미지 구문 : <img src="http://css-tricks.com/examples/WebsiteChangeRequestForm/images/wcrf-header.png" alt="Website Change Request" />'

$to = '[email protected]'; 

$subject = 'Website Change Request'; 

$headers = "From: " . strip_tags($_POST['req-email']) . "\r\n"; 
$headers .= "Reply-To: ". strip_tags($_POST['req-email']) . "\r\n"; 
$headers .= "CC: [email protected]\r\n"; 
$headers .= "MIME-Version: 1.0\r\n"; 
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; 

$message = '<html><body>'; 
$message .= '<img src="http://css-tricks.com/examples/WebsiteChangeRequestForm/images/wcrf-header.png" alt="Website Change Request" />'; 
$message .= '<table rules="all" style="border-color: #666;" cellpadding="10">'; 
$message .= "<tr style='background: #eee;'><td><strong>Name:</strong> </td><td>" . strip_tags($_POST['req-name']) . "</td></tr>"; 
$message .= "<tr><td><strong>Email:</strong> </td><td>" . strip_tags($_POST['req-email']) . "</td></tr>"; 
$message .= "<tr><td><strong>Type of Change:</strong> </td><td>" . strip_tags($_POST['typeOfChange']) . "</td></tr>"; 
$message .= "<tr><td><strong>Urgency:</strong> </td><td>" . strip_tags($_POST['urgency']) . "</td></tr>"; 
$message .= "<tr><td><strong>URL To Change (main):</strong> </td><td>" . $_POST['URL-main'] . "</td></tr>"; 
$addURLS = $_POST['addURLS']; 
if (($addURLS) != '') { 
    $message .= "<tr><td><strong>URL To Change (additional):</strong> </td><td>" . strip_tags($addURLS) . "</td></tr>"; 
} 
$curText = htmlentities($_POST['curText']);   
if (($curText) != '') { 
    $message .= "<tr><td><strong>CURRENT Content:</strong> </td><td>" . $curText . "</td></tr>"; 
} 
$message .= "<tr><td><strong>NEW Content:</strong> </td><td>" . htmlentities($_POST['newText']) . "</td></tr>"; 
$message .= "</table>"; 
$message .= "</body></html>"; 

mail($to,$subject,$message,$headers); 

코드 소스와 자세한 설명 : http://css-tricks.com/sending-nice-html-email-with-php/

관련 문제