PHP邮件表单不发送

时间:2015-09-03 21:21:49

标签: php forms email sendmail

我知道这是一个很受欢迎的问题。但是,没有其他问题可以给我我正在寻找的答案。

有一个联系表格(邮件()正在使用。我无法发送。一位帮我创建它的编码器让他发送,因为我在收件箱中收到了一些邮件邮件被编码发送给。我复制并粘贴了代码,我在本地测试它,但它没有发送邮件。

问题是它没有发送,因为我在本地测试并且它不是实时和托管的吗?或者问题是否依赖于我的代码,如果是,那么?

***不包括验证码,但我在那里......

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));
}

1 个答案:

答案 0 :(得分:0)

您的localhost中需要一个smtp服务器。否则你将无法发送它。