php邮件没有返回true或false,也没有返回指定的消息

时间:2013-12-29 01:59:50

标签: php forms post

我是php的新手,我遇到了php邮件功能的问题。我在实时服务器上测试,而不是localhost。当我完成表单时,我没有得到邮件功能的响应。我不确定我做错了什么。

         <?php 
if (($_SERVER['REQUEST_METHOD'] == 'POST') && (!empty($_POST['action']))):

if (isset($_POST['fullname'])) { $fullname = $_POST['fullname']; }
if (isset($_POST['email'])) { $email = $_POST['email']; }
if (isset($_POST['phone'])) { $phone = $_POST['phone']; }
if (isset($_POST['form_message'])) {
 $form_message = filter_var($_POST['form_message'], FILTER_SANITIZE_STRING); }

$form_errors = false;

if( $fullname === '') :
    $form_errors = true;
    endif;

if ($form_message === '') :
    $form_errors = true;
    endif;

if (!$form_errors) :
    $to = "email@address.com";
    $subject = "From $fullname --VTS Specialist Contact Form";
    $message = "$form_message";

    $replyto = "From: $email \r\n" .
               "Reply-To: email@address.com";


    if(mail($to, $subject, $message)):
        $msg = "Thanks for reaching out to VTS Specialist, We will get back to you as soon as possible!";
    else:
        $msg = " Sorry your message could not be sent, try again.";
    endif; # mail form data

endif; #check for form errors

endif;

?>

1 个答案:

答案 0 :(得分:1)

尝试在底部添加一个echo语句 - 正如Mario所提到的,你只是声明它,你没有显示它。


if(mail($to, $subject, $message)):
    $msg = "Thanks for reaching out to VTS Specialist, We will get back to you as soon as possible!";
else:
    $msg = " Sorry your message could not be sent, try again.";
endif; # mail form data

echo $msg;