在远程服务器上获取404但可以在本地服务器上打开页面

时间:2014-03-27 15:23:41

标签: php curl centos http-status-code-404 phpmailer

我遇到以下问题的问题。它应该向电子邮件服务器提供商发送电子邮件。它在本地服务器上工作得非常好,但是当我在远程服务器上测试它时,我总是得到:

404 Page Not Found
The page you requested was not found.

对于为何发生这种情况的任何想法都非常感激。

代码:

 public function index ()
 {   
    $recipient = $email;
    $title = 'You've got mail';
    $body = 'I love you!';

    $data=
    array(
    'api_user'=>'postmaster@sendcloud.org',
    'api_key' =>'password',
    'from'=>'raphael.luo@live.com',
    'to'=>$recipient,
    'subject'=>$title,
    'html'=>$body
    );

    $ch = curl_init();

    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);

    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
    curl_setopt($ch, CURLOPT_URL, 'https://sendcloud.sohu.com/webapi/mail.send.json');

    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);       

     $result = curl_exec($ch); 

     curl_close($ch);

    print_r($result);

}

1 个答案:

答案 0 :(得分:0)

这可能是安全通信的问题(您的网址有https://)。因此,如果您使用不安全的通信没有任何问题,请在您的代码中添加此curl选项,然后重试:

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);

http_build_query数据使用POST函数也始终是安全的。

curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));