채택완료

curl 를 php curl 로 변환중인데 약간 문제가 있는것같아요..

https://www.mailjet.com/email-api/

 

위에 curl를 이용해서 아래와같은 소스를 만들었습니다.

어떤이유에서인지 작동이 되지 않습니다..

어떤 이유일까요..;

 

 

 

Copy
<?php

 

$data = '{

        "Messages":[

{

                "From": {

                    "Email": "pilot@mailjet.com",

                    "Name": "Mailjet Pilot"

                },

                "To": [

                 {

                     "Email": "pilot@mailjet.com",

                        "Name": "passenger 1"

                    }

                ],

                "Subject": "Your email flight plan!",

                "TextPart": "Dear passenger 1, welcome to Mailjet! May the delivery force be with you!",

                "HTMLPart": "<h3>Dear passenger 1, welcome to Mailjet!</h3><br/>May the delivery force be with you!"

            }

        ]

    }';

 

$ch = curl_init();

curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);

curl_setopt($ch, CURLOPT_USERPWD, 'xxxxx');

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');

curl_setopt($ch, CURLOPT_POST, true);

curl_setopt($ch, CURLOPT_URL, 'https://api.mailjet.com/v3.1/send');

curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

$response = curl_exec($ch);

$info = curl_getinfo($ch);

curl_close($ch);

$response = json_decode($response);

 

if($info['http_code'] != 200) {

return false;

} else {

return true;

}


 

?>
|

답변 1개 / 댓글 3개

채택된 답변
+20 포인트

curl_setopt($ch,CURLOPT_SSLVERSION,1);

를 넣어보세요.

 

안 되면 1을 2, 3으로 바꿔보시구요.

답변에 대한 댓글 3개

3개다 해봤지만 안되네요 ㅎㅎ;
@떳다이장님 올려주신 코드 저는 정상 작동합니다. ($response에 값이 들어옵니다.)
curl 라이브러리가 안 깔린 것인지 등 php 환경을 점검해보세요.

그게 아니라면, var_dump($response) 를 하셔서 어떤 값이 나오는지 확인해보세요.
감사합니다 ㅎ 해결되었습니다.

답변을 작성하려면 로그인이 필요합니다.