doulun5683 2016-07-31 10:26
浏览 249

contact-form.php无效

My php contact form is not sending any emails to me. Please help me.

The form code:

                        <form action="php/contact-form.php" id="contact-form">
                      <div class="alert alert-success hidden" id="contact-alert-success" dir="rtl"> <strong>זה עבד!</strong> תודה שיצרת קשר. נחזור אליך מיד! </div>
                      <div class="alert alert-danger hidden" id="contact-alert-error" dir="rtl"> <strong>שגיאה!</strong> משהו השתבש בשליחת ההודעה. </div>
                      <div class="form-group" dir="rtl">
                        <label class="sr-only" for="name"></label>
                        <input dir="rtl" type="text" class="form-control" value="" placeholder="שם" data-msg-required="נא להזין שם." name="name" id="name">
                      </div>
                                                <div class="form-group" dir="rtl">
                        <label  class="sr-only" for="phone"></label>
                        <input type="text" value="" placeholder="טלפון" data-msg-required="נא להזין טלפון." data-msg-email="נא להזין טלפון תקין." class="form-control" name="phone" id="phone"  maxlength="10">
                      </div>
                      <div class="form-group" dir="rtl">
                        <label class="sr-only" for="email"></label>
                        <input type="email" value="" placeholder="דואר אלקטרוני" data-msg-required="נא להזין דואר אלקטרוני." data-msg-email="נא להזין כתובת תקינה." class="form-control" name="email" id="email">
                      </div>
                      <div class="form-group" dir="rtl">
                        <label class="sr-only" for="message"></label>
                        <textarea dir="rtl" placeholder="נא להזין את ההודעה..." data-msg-required="יש להזין הודעה." rows="6" class="form-control" name="message" id="message"></textarea>
                      </div>
                      <input type="submit" value="שלח הודעה" class="btn btn-default btn-block" dir="rtl" data-loading-text="טוען...">
                    </form>

the contact-form.php file is

<?php
session_cache_limiter('nocache');
header('Expires: ' . gmdate('r', 0));

header('Content-type: application/json');

// Enter your email address
$to = 'omanbbb@gmail.com';


if($to) {
    $name = $_POST['name'];
    $email = $_POST['email'];
    $phone = $_POST['phone'];

    $fields = array(
        0 => array(
            'text' => 'Name',
            'val' => $_POST['name']
        ),
        1 => array(
            'text' => 'Email address',
            'val' => $_POST['email']
        ),
        2 => array(
            'text' => 'Message',
            'val' => $_POST['message']
        ),      
        3 => array(
            'numbers' => 'Phone',
            'val' => $_POST['phone']
        )
    );

    $message = "";

    foreach($fields as $field) {
        $message .= $field['text'].": " . htmlspecialchars($field['val'], ENT_QUOTES) . "<br>
";
    }

    $subject = "New message from: $name";

    $headers = '';
    $headers .= 'From: ' . $name . ' <' . $email . '>' . "
";
    $headers .= "Reply-To: " .  $email . "
";
    $headers .= "MIME-Version: 1.0
";
    $headers .= "Content-Type: text/html; charset=UTF-8
";

    if (mail($to, $subject, $message, $headers)){
        $arrResult = array ('response'=>'success');
    } else{
        $arrResult = array ('response'=>'error');
    }

    echo json_encode($arrResult);

} else {

    $arrResult = array ('response'=>'error');
    echo json_encode($arrResult);

}
?>

Thank you very much.

  • 写回答

1条回答 默认 最新

  • dongling2545 2016-07-31 10:33
    关注

    you are not including the method in your form eg:

    <form action="php/contact-form.php" id="contact-form" method="post">
    

    which will allow your contact-form.php to access the values from the form inputs in the post super global array.

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器