0

this is the PHP email script that I want to use for my website. I am creating this website for my father's company, and decided to make it with Bootstrap. The HTML and CSS knowledge required was something I could still do, but this is beyond my knowledge. Somewhere on the Internet I dug up this script and it doesn't work for me. I am sure that there probably is a very logical reason for this, but I have no knowledge whatsoever of PHP-scripting... I was hoping you could help this newbie out. I am very much willing to learn, but to study PHP just for a simple script(I am not planning to do more web "development") seems a bit overexaggerating. Anyway, I am rambling on too much. Here is the script I found(I've called it: sendemail.php):

<?php
'success',
'message'=>'Thank you for contacting us. As soon as possible we shall be in touch with you '
);

    $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_ADRESS_HERE';

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

 $success = @mail($email_to, $subject, $body, 'From: <'.$email_from.'>');

    echo json_encode($status);
    die;
 ?>

Of course, I replaced the value from "email_to" with my email adress of choice, I tested even multiple email adresses and it simply doesn't work. I get the spinning icon with the "processing" text as defined in my main.js file, but that's it. It stays at that forever. I feel like this is also necessary to understand why the PHP-script isn't working(perhaps I'm wrong), but here is the relevant HTML code in the Bootstrap form:

    <section id="contact-page">
    <div class="container">
        <div class="center">
            <h2>Be in touch with us:</h2>
            <p class="lead">DUMMY TEXT</p>
        </div>
        <div class="row contact-wrap">
            <div class="status alert alert-success" style="display: none"></div>
            <form id="main-contact-form" class="contact-form" name="contact-form" method="post" action="sendemail.php">
                <div class="col-sm-5 col-sm-offset-1">
                    <div class="form-group">
                        <label>Name *</label>
                        <input type="text" name="name" class="form-control" required="required">
                    </div>
                    <div class="form-group">
                        <label>E-mail *</label>
                        <input type="email" name="email" class="form-control" required="required">
                    </div>
                    <div class="form-group">
                        <label>Phone</label>
                        <input type="number" class="form-control">
                    </div>
                    <div class="form-group">
                        <label>Company Name</label>
                        <input type="text" class="form-control">
                    </div>
                </div>
                <div class="col-sm-5">
                    <div class="form-group">
                        <label>Subject *</label>
                        <input type="text" name="subject" class="form-control" required="required">
                    </div>
                    <div class="form-group">
                        <label>Message *</label>
                        <textarea name="message" id="message" required="required" class="form-control" rows="8"></textarea>
                    </div>
                    <div class="form-group">
                        <button type="submit" name="submit" class="btn btn-primary btn-lg" required="required">Submit Message</button>
                    </div>
                </div>
            </form>
        </div>
</section>

If you require more information or anything, please tell and I will provide it immediately, because I am dying to get this to work.

Two things I want to highlight:

  1. The form was made with preset Bootstrap tags, and all of it Bootstrap. Maybe this affects the way the script works?
  2. I am working on this locally on my PC, so it isn't run from a server or anything. I still need to take it out for a test spin. I don't know if this affects the way the email is forwarded... Yeah, I am really a complete noob.

All help and tips are much appreciated and thank you in advance!

Mats Punt
  • 23
  • 2
  • 4
  • You don't need the @ in "@mail" same with trim – Demodave Apr 01 '15 at 14:08
  • why all the `@`'s before the function calls? Are you really that afraid `trim` will kill your app? – giorgio Apr 01 '15 at 14:08
  • `I'm working on this locally`, in that case I'm quite sure you haven't configured a mailserver on your local pc... Put your script on a live server, maintained by a professional, and test it there. – giorgio Apr 01 '15 at 14:11
  • Why not just use [PHPMailer](https://github.com/PHPMailer/PHPMailer) instead -- it'll work on local machines too, and it's pretty straightforward. – FloatingRock Apr 01 '15 at 14:13
  • as giorgio said, probably you don't have a mailserver in your PC. Instead to put your script on a live server, try to use PHPMailer. Ins't hard to use, and you can read the tutorial at the github page. https://github.com/PHPMailer/PHPMailer – ital0 Apr 01 '15 at 14:15
  • Wow, everyone, thank you so much for your input in this small time frame! I will definitely take a look at PHPMailer, because it looks amazing and I can't believe I came across it before. About the similarity with the other question, I swear that I searched very intensively before asking and I didn't come across that question. As I have said before, I am a total and complete noob at this stuff, so please forgive my ignorance, allthough I know you all have to put up with a lot of it... I will take a look at everything and come back if I didn't figure it out! Thanks everybody! – Mats Punt Apr 01 '15 at 14:27

1 Answers1

0

Probably your server manager is not configured to send mails. If you are you using Wamp, Xamp, even Apache itself on Linux, you will need to configure a mail server to do it.

Jhon
  • 1
  • 1