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

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

QA

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

답변 1

본문

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

 

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

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

어떤 이유일까요..;

 

 

 


<?php
 
$data = '{
        "Messages":[
{
                "From": {
                    "Email": "*** 개인정보보호를 위한 이메일주소 노출방지 ***",
                    "Name": "Mailjet Pilot"
                },
                "To": [
                 {
                     "Email": "*** 개인정보보호를 위한 이메일주소 노출방지 ***",
                        "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

curl_setopt($ch,CURLOPT_SSLVERSION,1);

를 넣어보세요.

 

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

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

그게 아니라면, var_dump($response) 를 하셔서 어떤 값이 나오는지 확인해보세요.

답변을 작성하시기 전에 로그인 해주세요.
QA 내용 검색
질문등록
전체 9
© SIRSOFT
현재 페이지 제일 처음으로