资源不支持指定的Http Verb

时间:2017-12-17 07:27:02

标签: cors sendmail azure-storage-blobs

我正在尝试为Azure blob中托管的静态网站创建联系表单。 当我单击提交时,我可以在控制台中看到以下错误。

Failed to load resource: the server responded with a status of 405 
(The resource doesn't support specified Http Verb.)

我认为问题可能是我需要为mailgun设置CORS。

但是我不知道要放什么值

enter image description here

这是send.php代码

<?php
if( isset($_POST) ){

    $postData = $_POST;
    $mailgun = sendMailgun($postData);

    if($mailgun) {
    echo "Great success.";
  } else {
    echo "Mailgun did not connect properly.";
  }
}

function sendMailgun($data) {

  $api_key = 'INSERT_API_KEY_HERE';
  $api_domain = 'INSERT_DOMAIN_HERE';
  $send_to = 'YOUR_EMAIL';

    // sumbission data
        $ipaddress = $_SERVER['REMOTE_ADDR'];
        $date = date('d/m/Y');
        $time = date('H:i:s');

    // form data
        $postcontent = $data['data'];
        $reply = $data['senderAddress'];  

  $messageBody = "<p>You have received a new message from the contact form on your website.</p>
                {$postcontent}
                <p>This message was sent from the IP Address: {$ipaddress} on {$date} at {$time}</p>";

  $config = array();
  $config['api_key'] = $api_key;
  $config['api_url'] = 'https://api.mailgun.net/v3/'.$api_domain.'/messages';

  $message = array();
  $message['from'] = $reply;
  $message['to'] = $send_to;
  $message['h:Reply-To'] = $reply;
  $message['subject'] = "New Message from your Mailgun Contact Form";
  $message['html'] = $messageBody;

  $curl = curl_init();

  curl_setopt($curl, CURLOPT_URL, $config['api_url']);
  curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  curl_setopt($curl, CURLOPT_USERPWD, "api:{$config['api_key']}");
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10);
  curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
  curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
  curl_setopt($curl, CURLOPT_POST, true); 
  curl_setopt($curl, CURLOPT_POSTFIELDS,$message);

  $result = curl_exec($curl);
  curl_close($curl);
  return $result;
}
?>

此问题是this question

的后续问题

我尝试在api_domain中包含子域名www。

1 个答案:

答案 0 :(得分:0)

PHP不运行客户端,这意味着它不适合静态网站。 As mentioned in this question 提到了替代方案here