0

So, here I have this bootstrap form which I want to send tickets to my gmail account from.

this is my html

<form name="sentMessage" id="contactForm" novalidate action="mail/contact.php" method="post" >
                    <div class="row">
                        <div class="col-md-6">
                            <div class="form-group">
                                <input type="text" class="form-control" placeholder="Your Name *" id="name" required data-validation-required-message="Please enter your name.">
                                <p class="help-block text-danger"></p>
                            </div>
                            <div class="form-group">
                                <input type="email" class="form-control" placeholder="Your Email *" id="email" required data-validation-required-message="Please enter your email address.">
                                <p class="help-block text-danger"></p>
                            </div>
                            <div class="form-group">
                                <input type="tel" class="form-control" placeholder="Your Phone " id="phone">
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <textarea class="form-control" placeholder="Your Message *" id="message" required data-validation-required-message="Please enter a message."></textarea>
                                <p class="help-block text-danger"></p>
                            </div>
                        </div>
                        <div class="clearfix"></div>
                        <div class="col-lg-12 text-center">
                            <div id="success"></div>
                            <button type="submit" class="btn btn-xl">Send Message</button>
                        </div>
                    </div>
                </form>

and here is my php which didn't work and after that I included action, method and enctype classes in html above.

<?php   //check empty fields
if(empty($_POST['name'])        || 
empty($_POST['email'])      ||
empty($_POST['message'])    ||
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
echo "No arguments Provided!";
return false;
}

$name = $_POST['name'];
$email_address = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];

$to = 'myemail@gmail.com'; 
$email_subject = "Website Contact Form:  $name";
$email_body = "You have received a new message from your website                 contact form.\n\n"."Here are the details:\n\nName: $name\n\nEmail:              

$email_address\n\nPhone: $phone\n\nMessage:\n$message";
$headers = "From: noreply@yourdomain.com\n"; //No email on the host, tried postmark inbound email address but no go.
$headers .= "Reply-To: $email_address"; 
mail($to,$email_subject,$email_body,$headers);
return true;            
?>

Thank you in advance

forkinspace
  • 124
  • 1
  • 3
  • 16
  • I'm using freehostingeu.com just for the sake of being free. Its my first website. They don't provide email account for free subscribers, and can't really install anything on the server or edit any software unless I upgrade to a paid service. I just added an email link and that will have to do for now I guess. I looked into the PHPMailer the other day and looks great, well documented and all. Sad I can't use it – forkinspace Jan 26 '16 at 13:23
  • Great! :D Looking forward. Thank you – forkinspace Jan 26 '16 at 13:55
  • Thank you Ryan. Your help is much appreciated. I do try to post a question here as a last resort but sometimes I feel like there are always some work arounds that i'm not aware of (even if it sounds next to impossible, like SSL disabled). Thank you again – forkinspace Jan 26 '16 at 15:34

2 Answers2

0

It's best to not use mailto: in your form action, it's enough that user will not have it configured properly and it will not work. Instead of mailto use address of your php script, also use method="post".

To actually send email in php you need to use mail function (they are better solutions then that, but more complicated).

You can find easy tutorial in here http://www.tutorialspoint.com/php/php_sending_emails.htm . You can probably skip configuration part as that should be set up on most of the servers already.

Maciej Paprocki
  • 1,230
  • 20
  • 29
  • NOTE: I'm hosting a page on a free hosting server and I can't edit php.ini, all I can do is assume that it's pre-configured – forkinspace Jan 26 '16 at 10:52
  • You will not have to. Everything should be set up properly on shared hostings (especially they need to use mails to work with cms), just start after php.ini part. – Maciej Paprocki Jan 26 '16 at 10:53
  • I get an error - it seems that mail server is not responding. Please try again later! – forkinspace Jan 26 '16 at 11:07
  • that means probably that your shared hosting is not set up properly. You should probably write to hosts. I am not really able to debug it without code and access to server, so sorry. – Maciej Paprocki Jan 26 '16 at 11:24
  • don't sweat it, thank you for your efforts. ;) – forkinspace Jan 26 '16 at 11:28
0

$to = 'myemail@gmail.com;

You're not closing your string. It should be like this:

$to = 'myemail@gmail.com'; 
Frank Drebin
  • 1,063
  • 6
  • 11