2014-02-14 2 views
13

mailgun 문서에서 내 문제에 대한 해결책을 찾지 못한 후 내가 찾고있는 것을 설명 할 것입니다.mailgun을 사용하여 HTML 전자 메일을 보내는 방법은 무엇입니까?

오늘 phpList를 사용하여 내 뉴스 레터를 발송합니다 (완벽하게 작동합니다!). PHP 페이지 응용 프로그램에 포함 된 HTML 페이지를 보내면됩니다. (나는 SMTP 방법을 사용하여 뉴스를 보내고있다). mailgun을 사용하여 동일한 작업을 수행 할 수 있는지 궁금합니다 (어떻게 할 수 있습니까?). HTML 페이지를 보내는 경로를 포함시킬 수 있습니까? (나는 스크립트에 내 HTML 코드를 입력하는 데 관심이 없다. 그렇지 않으면 경로에 있어야하는데 그렇지 않으면 나는 mailgun을 사용하지 않는다.)

다음과 같은 내 mailgun PHP 코드를 살펴 보자

$result = $mgClient->sendMessage("$domain", 
      array('from' => 'My Business Name <[email protected]>', 
       'to'  => '[email protected], [email protected], [email protected]', 
       'subject' => 'Issue Feb 2014', 
       'text' => 'Your mail do not support HTML', 
       'html' => '<html>Inline image: <img src="cid:Pad-Thai-1.jpg"></html>', 
       'recipient-variables' => '{"[email protected]": {"first":"Name-1", "id":1}, "[email protected]": {"first":"Name-2", "id": 2}}'), 
      array('inline' => 'Pad-Thai-1.jpg')); 

내가 나는 (수없는 경우, 내가 어디에 넣을 수 있습니다 내 HTML 페이지의 경로를 포함 할 것, 배열 요소는 'html'라는 이름의이를 그것?). 이 HTML 배열 요소에 전체 HTML 코드를 포함 할 수 없기 때문에 너무 광범위합니다.

그러나 메일 건은 쉽고 훌륭하다고 주장합니다. 그것은 내가 바꾸고 싶은 동기입니다.

+0

정말 mailgun 쌓아! 엉덩이 API에 통증이! – B4NZ41

답변

29

저는이 방법으로 외부 HTML 템플릿을 사용했습니다. 너에게 도움이 될지도 모른다.

$html = file_get_contents('my_template.html'); // this will retrieve the html document 

다음 :

$result = $mgClient->sendMessage("$domain", 
     array('from' => 'My Business Name <[email protected]>', 
      'to'  => '[email protected], [email protected], [email protected]', 
      'subject' => 'Issue Feb 2014', 
      'text' => 'Your mail do not support HTML', 
      'html' => $html, 
      'recipient-variables' => '{"[email protected]": {"first":"Name-1", "id":1}, "[email protected]": {"first":"Name-2", "id": 2}}'), 
     array('inline' => 'Pad-Thai-1.jpg')); 

확인이 라인 :

'html' => $html, 
+2

나는 당신과 똑같이했고 지금은 잘 작동합니다! $ 문제 = file_get_contents ('http : //xxxx.html'); $ batchMsg-> setHtmlBody ($ issue); 답을 올바르게 수락합니다! 감사. – B4NZ41

+1

JavaScript를 사용하여이를 달성하는 방법은 무엇입니까? – Anirudh

+0

아약스 요청을 보내면됩니다. – israr

2

Mailgun 문서에 대한 링크를 추가. 이것은 HTML과 MIME 메시지를 만드는 동안 도움이되었습니다. 문서 당으로 https://documentation.mailgun.com/api-sending.html#examples

:

# Include the Autoloader (see "Libraries" for install instructions) 
require 'vendor/autoload.php'; 
use Mailgun\Mailgun; 

# Instantiate the client. 
$mgClient = new Mailgun('YOUR_API_KEY'); 
$domain = "YOUR_DOMAIN_NAME"; 

# Make the call to the client. 
$result = $mgClient->sendMessage($domain, array(
    'from' => 'Excited User <[email protected]_DOMAIN_NAME>', 
    'to'  => '[email protected]', 
    'cc'  => '[email protected]', 
    'bcc'  => '[email protected]', 
    'subject' => 'Hello', 
    'text' => 'Testing some Mailgun awesomness!', 
    'html' => '<html>HTML version of the body</html>' 
), array(
    'attachment' => array('/path/to/file.txt', '/path/to/file.txt') 
)); 
관련 문제