2016-06-24 4 views
1

Mail Gun을 통해 첨부 파일이있는 이메일을 보내려는 api를 실행하는 중 일부 문제가 있습니다. 우편 배달부를 통해 api를 실행하려고했는데 완벽하게 실행되어 문제가없는 것으로 알고 있습니다. api하지만 코드를 통해 요청을 보낼 수 없습니다.HTTP를 통해 Mailgun으로 이메일 보내기 Curl을 사용하여 요청

나는 코드 예제 아래에 추가 한 :

<?php 
$curl_post_data=array(
    'from' => 'Excited User <[email protected]>', 
    'to'  => '[email protected]', 
    'subject' => 'Hello', 
    'text' => 'test' 
//,'attachment[1]' => '@https://www.smsglobal.com/docs/HTTP-2WAY.pdf' 
,array('attachment' => 'https://www.smsglobal.com/docs/HTTP-2WAY.pdf') 
); 

$service_url = 'https://api.mailgun.net/v3/test.com/messages'; 
$curl = curl_init($service_url); 
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); 
curl_setopt($curl, CURLOPT_USERPWD, "api:key-testtesttesttes"); 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($curl, CURLOPT_POST, true); 
curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data); 
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); 

$curl_response = curl_exec($curl); 
$response = json_decode($curl_response); 
curl_close($curl); 

var_dump($response); 

?> 

답변

2

내가 문제를 해결할 수 있었다.

내 결과 : 1-) 첨부 파일로 라이브 URL 주소를 부여 할 수 없습니다. http://test.com/images/logo.png이 작동하지 않습니다. 서버에서 호스팅되는 파일의 2)에만 주소를들 수있다 /var/images/logo.png

<?php 

$filePath='@0Wealth_AC_AMF.pdf'; 

$curl_post_data=array(
    'from' => 'Excited User <[email protected]>', 
    'to'  => '[email protected]', 
    'subject' => 'Hello', 
    'text' => 'test', 
'attachment[1]' => $filePath 
); 

$service_url = 'https://api.mailgun.net/v3/test.com/messages'; 
$curl = curl_init($service_url); 
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); 
curl_setopt($curl, CURLOPT_USERPWD, "api:key-test"); 

curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($curl, CURLOPT_POST, true); 

curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data); 
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); 


$curl_response = curl_exec($curl); 
$response = json_decode($curl_response); 
curl_close($curl); 

var_dump($response); 



?>