0

I want to ask what I should do to receive e-mails from my contact form. When i try to send a message it says that my message is sent, but I never receive it. Please help me.

here is my php code. What am I doing wrong?

<?php 
  $myemail = '#######@yahoo.co.uk';
//set validation error flag as false
$error = false;
//check if form is submitted
if (isset($_POST['submit']))
{
    $name = trim($_POST['txt_name']);
    $fromemail = trim($_POST['txt_email']);
    $subject = trim($_POST['txt_subject']);
    $message = trim($_POST['txt_msg']);

    //name can contain only alpha characters and space and greek letters
    if (!preg_match("/^[a-zA-Zα-ωΑ-Ωίϊΐόάέύϋΰήώςτσπρφχψ ]+$/",$name))
    {
        $error = true;
        $name_error = "Plsease insert name";
    }
    if(!filter_var($fromemail,FILTER_VALIDATE_EMAIL))
    {
        $error = true;
        $fromemail_error = "wrong mail";
    }
    if(empty($subject))
    {
        $error = true;
        $subject_error = "empty sub";
    }
    if(empty($message))
    {
        $error = true;
        $message_error = "message???";
    }
    if (!$error)
    {
        //send mail
        $toemail = $myemail;
        $subject = "Enquiry from Visitor " . $name;
        $body = "Here goes your Message Details: \n\n Name: $name \n From: $fromemail \n Message: \n $message";
        $headers = "From: $fromemail\n";
        $headers .= "Reply-To: $fromemail";

        if (mail ($toemail, $subject, $body, $headers))
        {
            $alertmsg  = '<div class="alert alert-success text-center">Cheers m8 for contact!</div>';
        }
            else
            {
            $alertmsg = '<div class="alert alert-danger text-center">something went wrong</div>';
            }
    }
}
?>

And my form

<div class="container">
 <?php if (isset($alertmsg)) { echo $alertmsg; } ?>
<div class="row">
    <div class="col-md-6 col-md-offset-3 well">
        <form role="form" class="form-horizontal" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="contactform">
        <fieldset>
            <legend>Φόρμα επικοινωνίας</legend>

            <div class="form-group">
                <div class="col-md-12">
                    <label for="txt_name" class="control-label">Όνομα</label>
                </div>
                <div class="col-md-12">
                    <input class="form-control" name="txt_name" placeholder="Όνομα" type="text" value="<?php if($error) echo $name; ?>" />
                    <span class="text-danger"><?php if (isset($name_error)) echo $name_error; ?></span>
                </div>
            </div>

            <div class="form-group">
                <div class="col-md-12">
                    <label for="txt_email" class="control-label">Email </label>
                </div>
                <div class="col-md-12">
                    <input class="form-control" name="txt_email" placeholder="Εισάγεται το email σας" type="text" value="<?php if($error) echo $fromemail; ?>" />
                    <span class="text-danger"><?php if (isset($fromemail_error)) echo $fromemail_error; ?></span> 
                </div>
            </div>

            <div class="form-group">
                <div class="col-md-12">
                    <label for="txt_subject" class="control-label">Θέμα</label>
                </div>
                <div class="col-md-12">
                    <input class="form-control" name="txt_subject" placeholder="Θέμα" type="text" value="<?php if($error) echo $subject; ?>" />
                    <span class="text-danger"><?php if (isset($subject_error)) echo $subject_error; ?></span>
                </div>
            </div>
izk
  • 234
  • 6
  • 19
DopeAt
  • 451
  • 3
  • 15
  • 2
    If you execute just `mail('mymail@yahoo.co.uk', 'TEST', 'Hello Hello');`, do you get an e-mail? If not, you/ your provider has to set up PHP to send e-mails. – KIMB-technologies Mar 17 '16 at 13:16
  • i just tried that.... No idont get any e-mail :( – DopeAt Mar 17 '16 at 13:27
  • If you have PHP on a local computer there will be no good way to get it working. If you are on a server, ask you hoster! – KIMB-technologies Mar 17 '16 at 13:30
  • yes im on a server with free hosting trying to build my forst website and thats my only problem.... Eveything works fine but this.... I will contact them and ask... Thank you for your response mate – DopeAt Mar 17 '16 at 13:34
  • yes it was providers issue... Tnx a lot my friend... You make my day :D :D :D – DopeAt Mar 17 '16 at 13:42

1 Answers1

-1

Maybe you have to install postfix first (if your website use linux as environment).