0

I'm trying to get my webpage send out email from the contact form. Page is simple, made in html and added an php contact form.

This is installed on a opensuse leap 15 server, with nginx and php8 installed.

When trying to send from contact form I get

405 Not Allowed


nginx/1.21.5

I have tried to figure out how I can get the php form to allow me on opensuse. From what I see there is not any phpmailer packages for opensuse, like it is for other distroes (Used that on centos before changing to opensuse)

My php mailer file.

<?php
if ($_POST) {
    $to = 'emailaddress';
    $name = $_POST['name'];
    $email = $_POST['email'];
    $header = $_POST['header'];
    $message = $_POST['message'];
    $mes = "Navn: $name \nE-post: $email \nEmne: $header \nMelding: $message";
    if ($mes) {
        mail($to, $header, $mes, "Content-type:text/plain; charset = UTF-8\r\nFrom:$email");
    }
} else {
    header('Location: /');
    exit;
}

And this is the html codes for the form

<div id="contact_us" class="modal fade modal-contact-us" role="dialog">
        <div class="modal-dialog">
          <!-- Modal content-->
          <div class="modal-content">
            <div class="modal-header-contact">
              <h4 class="text-capitalize fwSemi-bold">Contact us</h4>

              <span class="close" data-dismiss="modal"></span>
            </div>

            <div class="model-body-contact">
              <form
                action="mailer.php"
                class="needs-validation"
                novalidate
              >

                <div class="control-container">
                  <label class="fwbold" for="modal-contact-name">Name *</label>
                  <input
                    class="form-control"
                    type="text"
                    id="modal-contact-name"
                    required
                    name="name"
                    minlength="2"
                  />
                </div>

                <div class="control-container">
                  <label class="fwbold" for="modal-contact-email"
                    >Email *</label
>
                  <input
                    class="form-control"
                    type="text"
                    id="modal-contact-email"
                    required
                    pattern="^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$"
                    name="email"
                  />
                </div>

                <div class="control-container">
                  <label class="fwbold" for="modal-contact-phone">Phone</label>
                  <input
                    class="form-control"
                    type="text"
                    id="modal-contact-phone"
                    pattern="^[0-9]+$"
                  />
                </div>

                <div class="control-container">
                  <label class="fwbold" for="modal-contact-message"
                    >Melding</label
                  >
                  <textarea
                    id="modal-contact-message"
                    name="message"
                  ></textarea>
                </div>

                <input
                  type="text"
                  class="hidden"
                  name="header"
                  value="Question"
                />

                <!--                                                    <input type="text" class="hidden" name="FM_ContactForm[receipient]" value="mailaddress">-->
                <!--                                                    <input type="text" class="hidden" name="FM_ContactForm[sentFrom]" value="">-->
                <!--                                                    <input type="text" class="hidden" name="ua" value="1">-->
                <!--                                                    <input type="text" class="hidden" name="id" value="33">-->
                <!--                                                    <input type="text" class="hidden" name="action" value="Contact">-->
                <!--                                                    <input type="text" class="hidden" name="blockId" value="">-->

                <div class="modal-contact-us-actions">
                  <button
                    class="btn btn-link round cancel-btn"
                                        type="button"
                    data-dismiss="modal"
                  >
                    Avbryt
                  </button>
                  <button
                    class="btn-primary btn-blue md-round fwSemi-bold send-btn"
                    type="submit"
                  >
                    Send
                  </button>
                </div>
              </form>
            </div>
          </div>
        </div>
      </div>

Tried to install sendmail instead of postfix to see if that helps, turned off firewall, tried to find phpmailer for opensuse distro

  • A 405 Not Allowed error likely has nothing to do with your form or your PHP. https://stackoverflow.com/a/38747204/2844703 – James May 24 '23 at 18:51
  • 1
    You're missing `method='post'` on your form attribute. The default method is `get` – aynber May 24 '23 at 19:05
  • @aynber while that's true, the form provided wouldn't give a 405 error and does account for non-POST requests (if ($_POST) {...} ). – James May 25 '23 at 01:55
  • Thanks for the replies, and yes you are right, after investigating more during the night i figured out that my nginx.conf file was missing this "error_page 405 =200 $uri". After adding that i was able to post. – Thomas Borge May 25 '23 at 07:06

0 Answers0