简体   繁体   English

PHP联系表格未通过电子邮件发送所有字段

[英]PHP Contact Form not emailing all fields

I have VERY little experience with PHP. 我对PHP的经验很少。

I am testing out a contact form for this website. 我正在测试该网站的联系表格。 I am only getting the "subject, message, and header" fields in the email. 我在电子邮件中仅收到“主题,消息和标题”字段。

I need the telephone and name fields to show in my email message as well. 我还需要电话和姓名字段显示在我的电子邮件中。

What am I doing wrong? 我究竟做错了什么?

Any help is appreciated -- thanks! 任何帮助表示赞赏-谢谢!

<?php

    $name;$email;$message;$captcha;$telephone;
    if(isset($_POST['name'])){
      $name=$_POST['name'];
    }if(isset($_POST['email'])){
      $email=$_POST['email'];
      }if(isset($_POST['telephone'])){
      $telephone=$_POST['telephone'];
    }if(isset($_POST['message'])){
      $message=$_POST['message'];
    }if(isset($_POST['g-recaptcha-response'])){
      $captcha=$_POST['g-recaptcha-response'];
    }
    if(!$captcha){
      echo '<h2>Please check the the captcha form. <a href=http://www.website.com#contact/>Back to Form</a></h2>';
      exit;
    }
    $response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=6LcYjgcT****q9vhur7iH_O4dZPl4xUAVwW8=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']);
    if($response.success==false)
    {
      echo '<h2>You are spammer ! Get the @$%K out</h2>';
    }else
    {
    // Checking For Blank Fields..
if ($_POST["name"] == "" || $_POST["email"] == "" || $_POST["telephone"] == "" || $_POST["message"] == "") {
    echo "Fill All Fields..";
} else {
    // Check if the "Sender's Email" input field is filled out
    $email = $_POST['email'];
    // Sanitize E-mail Address
    $email = filter_var($email, FILTER_SANITIZE_EMAIL);
    // Validate E-mail Address
    $email = filter_var($email, FILTER_VALIDATE_EMAIL);
    if (!$email) {
        echo "Invalid Sender's Email";
    } else {
        $to = 'email@gmail.com';
        $subject = 'Contact Form';
        $message = $_POST['message']; 
        $name = $_POST['name'];
        $headers = 'From:' . $email . "\r\n";
        // Sender's Email
        // Message lines should not exceed 70 characters (PHP rule), so wrap it
        $message .= "\r\n Name: " . $name;
        $message .= "\r\n Email: " . $email;
        $message .= "\r\n Telephone: " . $telephone;
        $message .= "\r\n Message: " . $message;
        // Send Mail By PHP Mail Function
        if (mail($to, $subject, $message, $headers)) {
            echo "Your mail has been sent successfully!<a href=http://wwwwebsite.com>Back</a>";
        } else {
            echo "Failed to send email, try again.";
            exit ;
        }
    }
}

} ?> }?>

The $message variable is the content of the mail that will be sent to your adress, add the values you want to get in your mail to that variable. $message变量是将发送到您的地址的邮件的内容,将要从邮件中获取的值添加到该变量。

like so : (since you're not using HTML mail I think) 就像这样:(因为我不使用HTML邮件)

$message .= "\r\n Name : " . $name;
$message .= "\r\n Email : " . $email;

etc.. 等等..

Before you call the mail function. 在调用mail功能之前。

ALSO : 还:

You're adding Phone number, Email, and message in your $email variable. 您正在$email变量中添加电话号码,电子邮件和消息。 you should give these their own variable. 您应该给它们自己的变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM