0

I know this is a popular question. However no other questions can give me the answer I'm looking for.

Have a contact form (mail() being using. And I can't get it to send. A coder that helped me create it somehow got his to send, because I received a few messages in my inbox the mail was coded to send to. I copy and pasted the code, and I'm testing it locally, but it's not sending the mail.

Is the problem it's not sending because I'm testing it locally and its not live and hosted yet? or does the problem rely in my code, and if so, where?

***Not including the validation code, but I have it there...

FORM:

<form method="post" action="">
                <input type="text" name="name" placeholder="*Name" value="<?php echo $_POST['name']; ?>">
                <input type="tel" name="phone" placeholder="*Phone Number" value="<?php echo $_POST['phone']; ?>">
                <input type="email" name="email" placeholder="*Email" value="<?php echo $_POST['email']; ?>">
                <input type="text" name="invoice" placeholder="Invoice Number (optional)" value="<?php echo $_POST['invoice']; ?>">
                <textarea name="comments" maxlength="500" rows="10" cols="10" placeholder="*Please enter your comments here..."><?php echo htmlentities($_POST['comments'], ENT_COMPAT,'ISO-8859-1', true);?></textarea>
                <button type="submit">Submit</button>
            </form>  

PHP:

if(!empty($_POST)){
$POST = filter_post($_POST);
$invoice = array_splice($POST,3,1);
$MSG = check_empty($POST);
$email = test_input($_POST["email"]);

if(!array_filter($MSG)){
    if(!filter_var($email, FILTER_VALIDATE_EMAIL)){
    $MSG[] = "Invalid Email Format (test@provider.com)";
    }
    else{
        $POST['invoice'] = $invoice['invoice'];
        if(send_mail($POST)){
            header('Location: messageSent.php');
        }
        else{
            $MSG[] = "Email Failed. Please Try Again.";
        }
    }
}
}



function send_mail($POST){
extract($POST);
$to = '7servicerepairs@gmail.com';
$sbj = 'New Question For Se7en Service!';
$msg = "Name: $name \n Phone: $phone \n Email: $email \n Invoice #: $invoice \n Comments: $comments";
$headers = "From: $email";
return(mail($to, $sbj, $msg, $headers));
}
blackRob4953
  • 1,585
  • 2
  • 12
  • 15

1 Answers1

0

You will need an smtp server in your localhost. Otherwise you won't be able to send it.

taxicala
  • 21,408
  • 7
  • 37
  • 66