Jump to content

Form not sending email??


mikebyrne

Recommended Posts

I'm using a template which contains a form so users can email me, but it doesn't seem to be working. Any ideas why??

I've changed "me@myemailaddress.com" to my own!

 

<?php

//Prefedined Variables
$to = "me@myemailaddress.com";

// Email Subject
$subject = "Contact from Your Site";

// This IF condition is for improving security  and Prevent Direct Access to the Mail Script.
if ($_POST) {

// Collect POST data from form
    $name = stripslashes($_POST['fname']);
    $email = stripslashes($_POST['email']);
    $phone = stripslashes($_POST['phone']);
    $message = stripslashes($_POST['msg']);
//$realcap = stripslashes($_POST['captcha']);

    $ipAddress = $_SERVER['REMOTE_ADDR'];
    if (array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER)) {
        $ipAddress = array_pop(explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']));
    }

// Collecting all content in HTML Table
    $content = '<table width="100%">
<tr><td  align "center"><b>Contact Details</b></td></tr>
<tr><td>Name:</td><td> ' . $name . '</td></tr>
<tr><td>Email:</td><td> ' . $email . ' </td></tr>
<tr><td>Phone:</td><td> ' . $phone . ' </td></tr>
<tr><td>Message:</td> <td> ' . $message . '</td></tr>
<tr><td>Date:</td> <td> ' . date('d-m-Y') . '</td></tr>
<tr><td>IP:</td> <td> ' . $ipAddress . '</td></tr>
</table> ';


// Define email variables
    $headers = "From:" . $email . "\r\n";
    $headers .= "Reply-to:" . $email . "\r\n";
    $headers .= 'Content-type: text/html; charset=UTF-8';

    if (!empty($name) && !empty($email) && !empty($content)) {
// Sending Email
        if (mail($to, $subject, $content, $headers)) {
            print "Thank you, I will getback to you shortly<br>";
            return true;
        } else {
            print "Some errors to send the mail.";
            return false;
        }
    } else {
        print "Some validation errors to send the mail.";
        return false;
    }
}

 

Link to comment
Share on other sites

"Doesn't seem to be working" is absolutely useless information for us. Of course it isn't working. It's why you made this thread.

How is it not working? Which message do you see? What have you tried to troubleshoot or solve the problem on your own?

Link to comment
Share on other sites

To add to all that, your use of returns confuses me. How is this file run? Do you know that return only matters if the code is inside a function or include/require-d from somewhere else?

edit: return can end a file early, but a return value only matters in the above two cases.

Link to comment
Share on other sites

Do you know that there are no other syntax-type errors going on?  Do you have PHP error checking turned on and displaying errors during development on your screen?

Try putting an echo ahead of the call to the mail function to be sure that you are getting that far.  Basic debugging process.

Link to comment
Share on other sites

11 minutes ago, Barand said:

 

            <!-- our services -->

            <section id="contact" class="bg-light-teal">

                <div class="content-boxed">

                    <div class="split-color wow fadeInLeft">

                        <div class="section-number">#05</div>

                        <h2 class="section-heading rotate">Contact</h2>

                    </div>

                    <div class="container-fluid">

                        <div class="row">

                            <div class="col-lg-6">
                                <div class="pr-5 mb-5 wow fadeInUp">

                                    <div class="gmap behind-border-box"><iframe src="https://www.google.com/maps/embed?pb=!1m14!1m8!1m3!1d2401.5623741248505!2d-6.9729973!3d52.9922718!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x485d6f8aac9336c9%3A0x35a64aae423e6da9!2sIrish+Web+Services!5e0!3m2!1sen!2sin!4v1531902216161" width="100%" height="450" frameborder="0" style="border:0" allowfullscreen></iframe>
</div>

                                </div>
                            </div>

                            <div class="col-lg-6">
                                <div class="wow fadeInRight">

                                    <h3>let’s get in touch</h3>

                                    <div class="contact-form">

                                        <form id="contact_form">

                                            <div class="f-field"><input name="fname" type="text" placeholder="Name" required></div>

                                            <div class="f-field"><input name="email" type="text" placeholder="Email" required></div>

                                            <div class="f-field"><input name="phone" type="text" placeholder="Phone" required></div>

                                            <div class="f-field"><textarea name="msg" placeholder="Message"></textarea></div>

                                            <div class="sent-btn"><input name="submit" type="submit" value="Submit"></div>

                                        </form>

                                    </div>

                                </div>
                            </div>

                        </div>

                    </div>

                    <h2 class="section-heading2">Contact</h2>

                </div>

            </section>

            <!-- our contact -->

 

Link to comment
Share on other sites

57 minutes ago, mac_gyver said:

your form is not a post method form, so there is no $_POST data.

add method='post' to the <form ... > tag.

  <form id="contact_form" method='post'>

                                            <div class="f-field"><input name="fname" type="text" placeholder="Name" required></div>

                                            <div class="f-field"><input name="email" type="text" placeholder="Email" required></div>

                                            <div class="f-field"><input name="phone" type="text" placeholder="Phone" required></div>

                                            <div class="f-field"><textarea name="msg" placeholder="Message"></textarea></div>

                                            <div class="sent-btn"><input name="submit" type="submit" value="Submit"></div>

                                        </form>

Still the same result. No error msg etc

Link to comment
Share on other sites

1 minute ago, Barand said:

Without an "action" attribute it is assumed that the processing code is on the same page as the form (ie the page calls itself). is that the case?

No, its on a separate page called contactsubmit.php

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.