seanscal
seanscal

Reputation: 568

cannot POST .php email

Whenever I try to send myself an email using the following code, I keep getting this error:

Cannot POST /assets/php/sendemail.php

I am not familiar enough with php to debug this, and everything I have tried so far doesn't seem to be working out.

The php file is in the correct directory, so I do know at least that much is correct.

Any help in debugging would be great, thank you!


My HTML code:

<div class="col-md-6">
<div class="contact-form">
    <strong>Send me a message</strong>
    <form name="contact-form" method="post" action="assets/php/sendemail.php">
        <div class="form-group">
            <label for="InputName1">Name</label>
            <input type="text" name="name" class="form-control" id="InputName1" required="">
        </div>
        <div class="form-group">
            <label for="InputEmail1">Email</label>
            <input type="email" name="email" class="form-control" id="InputEmail1" required="">
        </div>
        <div class="form-group">
            <label for="InputSubject">Subject</label>
            <input type="text" name="subject" class="form-control" id="InputSubject">
        </div>
        <div class="form-group">
            <label for="InputTextarea">Message</label>
            <textarea name="message" class="form-control" id="InputTextarea" rows="5" required=""></textarea>
        </div>

        <button type="submit" name="submit" class="btn btn-primary">Send Message</button>
    </form>
</div>

My PHP code:

$name = @trim(stripslashes($_POST['name']));
$email = @trim(stripslashes($_POST['email']));
$subject = @trim(stripslashes($_POST['subject']));
$message = @trim(stripslashes($_POST['message']));

$email_from = $email;
$email_to = '[email protected]'; //replace with your email

$body = 'Name: ' . $name . "\n\n" . 'Email: ' . $email . "\n\n" . 'Subject: ' . $subject . "\n\n" . 'Message: ' . $message;

$success = @mail($email_to, $body, 'Name: ' . $name . "\n\n" . 'Email: ' . $email . "\n\n" . 'Subject: ' . $subject . "\n\n" . 'Message: ' . $message);

Folder Structure:

Use server on OpenShift

enter image description here

Upvotes: 0

Views: 1057

Answers (3)

newman
newman

Reputation: 2719

There is not problem with PHP. Request just stop on web server and don't passed to PHP backend.

I think it need configure in OpenShift. Now server allow only GET request. I'm don't know how configure it. Try with options in control panel or in config files. Or ask hosting support team.

Upvotes: 0

Nitin Sali
Nitin Sali

Reputation: 337

First you can debug by keeping php code on page. I mean in <?php tag use

if(isset($_POST['submit'])){echo "<pre>"; print_r($_POST); }

you can print array like above so you come to know is it coming into that scope or something else.

Upvotes: 1

Eduardo Salazar
Eduardo Salazar

Reputation: 187

For debug add this 2 lines after <?php, just like this:

<?php
ini_set('display_errors', 'On');
error_reporting(E_ALL);

Then display the content of the variable you are debugging.

var_dump($_POST);

I suggest you to use a extension or library, i've used Xdebug a couple of times and worked for me.

Upvotes: 0

Related Questions