2016-08-08 4 views
1

전자 메일에서 내 데이터베이스에있는 이미지 디렉토리 (example.com/upload/pic.jpg)를 표시하지만 작동하지 않는 것처럼 보입니다.데이터베이스에서 긴 텍스트를 추출하고 데이터베이스에서 이미지 URL을 가져옵니다.

+0

'$ captain_image = $ 행 [ "imagesPath"]의 값이 무엇인가,'? 전체 서버 URL 대신 로컬 경로를 추측하고 있습니다. 또한 HTML로 보내야합니다. –

+0

* (이미지 디렉토리 (예.com/upload/pic.jpg) * - 이것이 실제 값인 경우 잘못된 것입니다. 'http : // example.com/upload/pic.jpg' 또는'http : // www.example.com/upload/pic.jpg '와 같이 www가 추가 된 상태로 읽어야합니다. html로 보내기. –

+0

@ Fred-ii-는 데이터베이스에서 단지 images/pic.jpg입니다. HTML로 보내기, 제발 좀 더 명확히 할 수 있을까요? –

답변

1

주석에 쓴 것처럼 이미지에 로컬 컴퓨터의 경로가 아닌 전체 URL이 필요하고 img src이 필요하며 HTML로 보내야합니다. .

즉 :

<img src="http://www.example.com/image.jpg">

그런 다음 방문, HTML로 PHP.net 웹 사이트를 보낼 : 그것은 예제가 들어

을,하지만 난 여기에 하나를 게시하고 mail() 기능을 수동에서 가져온 것입니다 :

<?php 
// multiple recipients 
$to = '[email protected]' . ', '; // note the comma 
$to .= '[email protected]'; 

// subject 
$subject = 'Birthday Reminders for August'; 

// message 
$message = ' 
<html> 
<head> 
    <title>Birthday Reminders for August</title> 
</head> 
<body> 
    <p>Here are the birthdays upcoming in August!</p> 
    <table> 
    <tr> 
     <th>Person</th><th>Day</th><th>Month</th><th>Year</th> 
    </tr> 
    <tr> 
     <td>Joe</td><td>3rd</td><td>August</td><td>1970</td> 
    </tr> 
    <tr> 
     <td>Sally</td><td>17th</td><td>August</td><td>1973</td> 
    </tr> 
    </table> 
</body> 
</html> 
'; 

// 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 .= 'To: Mary <[email protected]>, Kelly <[email protected]>' . "\r\n"; 
$headers .= 'From: Birthday Reminder <[email protected]>' . "\r\n"; 
$headers .= 'Cc: [email protected]' . "\r\n"; 
$headers .= 'Bcc: [email protected]' . "\r\n"; 

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

기본적으로 추가 http://www.example.com/을 이미지의 기존 변수에 추가 할 수 있습니다. 마지막에 슬래시를 잊지 마세요.

은 즉 :

$captain_image = "http://www.example.com/". $row["imagesPath"]; 

하고 mailout에서 img src 코드의 $captain_image 변수를 사용합니다. 따옴표

즉 :

<img src="$captain_image">.

그러나 코드의 경우 변수 선언 내에서 $captain_image의 큰 따옴표는 \으로 이스케이프 처리됩니다. (이 적절한 HTML 마크 업을 동시에 구문 분석 오류가 발생하지 않도록하기 위해 중요하다) : HTML로 보낼 때 라인

$message_coordinator .= "Image: <img src=\"$captain_image\"><br>"; 

사용 <br> 바꿈.

  • (!) 참고 : 변수는 작은 따옴표로 해석되지 않기 때문에 <img src='$captain_image'>이 실패하고 이미지 만이 아니라 변수 이름을 표시합니다.

PHPMailer 사용을 고려하면 삶이 훨씬 쉬워 질 것입니다.

또는 Swiftmailer :

관련 문제