2016-06-03 5 views
2

전자 메일 본문으로 html 테이블을 보내야합니다. 난 그냥 콘텐츠 형식을 HTML로 언급하려면 아래 않았다,하지만 작동하지 않았다.메일 본문을 컬링으로 html로 설정하는 방법은 무엇입니까?

headers = curl_slist_append(headers, "Content-Type: text/html"); 
/* pass our list of custom made headers */ 
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); 

도서관 사이트에서 예제를 찾을 수 없습니다.

답변

3

CURLOPT_HTTPHEADER 는 SMTP 옵션 (CURLOPT_MAIL_FROM, CURLOPT_MAIL_RCPT, CURLOPT_MAIL_AUTH)의 작동하지 않습니다를 참조하십시오. 대신 CURLOPT_READFUNCTION을 사용해야합니다.

/* Disclaimer: untested code */ 
char *msg = "To: [email protected]\r\n" 
      "From: [email protected]\r\n" 
      "Content-Type: text/html; charset=us-ascii\r\n" 
      "Mime-version: 1.0\r\n" 
      "\r\n" 
      "<html><head>\r\n" 
      "<meta http-equiv=\"Content-Type\" content="text/html; charset=us-ascii\">\r\n" 
      "</head><body>\r\n" 
      "<p>Hi Bob</p>\r\n" 
      "</body></html>\r\n" 

size_t callback(char *buffer, size_t size, size_t nitems, void *instream) { 
    /* you actually need to check that buffer <= size * nitems */ 
    strcat(buffer, msg); 
    return strlen(buffer); 
} 

curl_easy_setopt(curl, CURLOPT_READFUNCTION, callback); 
curl_easy_perform(curl); 

documentation for CURLOPT_READFUNCTION에 대한 자세한 정보가 있습니다. 이미 일반 텍스트 전자 메일을 보내고 있다면 이미 그곳에 왔습니다.

sameerkn에 의해 연결 Sending Mail Through Curl에 제시되지 않은 여기 유일한 "트릭"은 단순히 이메일 버퍼 내부의 Content-Type 헤더를 덤프 것입니다. HTTP와 같이 영리한 헤더 설정은 없습니다.


는 또한 : 난 당신이 Content-Transfer-Encoding 헤더를 필요가 있는지 확실하지 않다, 나는 us-ascii에 위의 charset을 설정했지만 utf-8 같은 것들이 전송 인코딩을해야 할 수도 있습니다.

+0

감사합니다. grochmal,이 사람이 정말로 도움이되었습니다. –

1

curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); 귀하의 요청에HTTP 프로토콜 헤더를 설정합니다.

게재중인 헤더는 전자 메일 데이터 (헤더 섹션)에 적용됩니다.

전자 메일 데이터 형식 :

Header: value 
Header: value 
Content-Type: text/html; charset="UTF-8" 
//**********************// << this is a blank line between Header and Body 
Body Of Mail 

이메일은 HTML을 포함합니까 (그것은 빈 라인으로 분리 된 2 개 섹션 헤더와 본문을 가지고)? 뿐만 아니라 이메일 헤더에 다음과 같은 헤더를 추가

봅니다 : Content-Transfer-Encoding

Content-Transfer-Encoding: quoted-printable 
Content-Type: text/html; charset="UTF-8" 

quoted-printable하여 HTML 데이터에 수행 인코딩입니다. 데이터를 base64으로 인코딩 할 수도 있습니다.

Content-Transfer-Encoding: base64 

** 편집 : 당신이 사용하여 메일을 보내려고하는 경우 컬 다음 Send Mail Through CURL

+0

이것은 나를 위해 작동하지 않았다. 나는 헤더 = curl_slist_append (헤더, "Content-Transfer-Encoding : base64;"); headers = curl_slist_append (헤더, "Content-Type : text/html; charset = \"UTF-8 \ ";"); /* 커스텀 메이크 헤더의리스트를 건네줍니다. */ curl_easy_setopt (curl, CURLOPT_HTTPHEADER, headers); –

+0

CURL을 통해 메일을 보내시겠습니까? – sameerkn

+0

예, 늦게 답변을 드려 죄송합니다. 도와 주셔서 감사합니다. 위와 같이 제공 한 헤더 옵션을 사용하여 직접 작성했습니다. –

관련 문제