1

I am trying to make a contact form for a static website hosted in an Azure blob. When I click submit I can see the following error in the Console.

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

I think the issue may be that I need to set up CORS for mailgun.

However I don't know what values to put

enter image description here

Here is send.php code

<?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 is a follow up from this question

I have tried including the subdomain www in the api_domain.

sideshowbarker
  • 81,827
  • 26
  • 193
  • 197
Kirsten
  • 15,730
  • 41
  • 179
  • 318

1 Answers1

0

PHP does not run client side which means it is not suitable for a static website. As mentioned in this question Alternatives are mentioned here

Kirsten
  • 15,730
  • 41
  • 179
  • 318