我怎么能用html联系表发送php邮件

时间:2017-05-29 21:07:22

标签: php html email

我目前正在尝试使用php mail()函数发送HTML联系表单或其内容。挂断电话请求帮助。

我该怎么做?您输入的文本和通过PHP在联系表单中指定的电子邮件地址?

所以我的代码目前看起来很有效..只是我不知道我输入的数据是如何发送的......

HTML代码:

          <form class="" action="senden.php" method="post">
            <div class="">
              <label>Name</label>
              <input type="text" name="von" placeholder="Bitte geben Sie Ihren Namen ein" value="">
              <label>E-Mail Adresse</label>
              <input type="text" name="email" placeholder="Bitte geben Sie Ihre Email-Adresse ein" value="">
              <label>Telefonnummer</label>
              <input type="tel" name="tel" placeholder="Bitte geben Sie Ihre Telefonnummer ein" value="">
            </div>
            <div class="">
              <label>Nachricht</label>
              <textarea placeholder="Bitte geben Sie Ihre Nachricht ein" name="nachricht" rows="8" cols="40"></textarea>
              <button type="submit" name="submit" value="">Nachricht Abschicken</button>
            </div>

          </form>

`

PHP代码:

<?php
          $empfaenger = "mymail@gmail.com";
          $betreff = "Mail Function";
          $from = "From: Max Reimers <absender@domain.de>";
          $text = "Email Email Email Email Text Text Text";

          mail($empfaenger, $betreff, $text, $from);
?>

1 个答案:

答案 0 :(得分:1)

这是代码:

&#13;
&#13;
<form class="form-horizontal" action="" id="contact-form" method="post">
                    <fieldset>
                        <legend class="text-center colheader">Email Us</legend>
                        <div class="form-group">
                            <div class="col-md-10 col-md-offset-1">
                                <input id="name" name="name" type="text" placeholder="Full Name" class="form-control" required>
                            </div>
                        </div>
                        

                        <div class="form-group">
                            <div class="col-md-10 col-md-offset-1">
                                <input id="email" name="email" type="text" placeholder="Email Address" class="form-control" required>
                            </div>
                        </div>

                        <div class="form-group">
                            <div class="col-md-10 col-md-offset-1">
                                <input id="phone" name="phonenumber" type="text" placeholder="Phone" class="form-control" required>
                            </div>
                        </div>
                    <div class="form-group">
                            <div class="col-md-10 col-md-offset-1">
                                <input id="subject" name="subject" type="text" placeholder="Subject" class="form-control">
                            </div>
                        </div>
                        
                        <div class="form-group">
                            <div class="col-md-10 col-md-offset-1">
                                <textarea class="form-control" id="message" name="messag" placeholder="Enter your massage for us here. We will get back to you within 2 business days." rows="7" required></textarea>
                            </div>
                        </div>

                        <div class="form-group">
                            <div class="col-md-12 text-center">
                                <button type="submit" name="submit" class="btn btn-primary btn-lg">Submit</button>
                            </div>
                        </div>
                    </fieldset>
                </form>
<?php 
if(isset($_POST['submit'])) {
    
    $to = 'ourmail@example.com'; 
    $from = $_POST['email']; 
    $subject ='Adlivetech Contact Form';
    $name = $_POST['name']; 
    $email = $_POST['email']; 
    $phone = $_POST['phonenumber'];
    $subject = $_POST['subject']; 
    $messag = $_POST['messag']; 
   

$message = '<html><body>';

$message .='<table>';
$message .='<tr><td>Name:</td><td>'. $name .'</td></tr>';

$message .='<tr><td>Email:</td><td>'. $email .'</td></tr>';

$message .='<tr><td>Phone:</td><td>'. $phone .'</td></tr>';

$message .='<tr><td>Subject:</td><td>'. $subject .'</td></tr>';

$message .='<tr><td>Message:</td><td>'. $messag .'</td></tr>';

$message .='</table>';

$message .='</body></html>';


$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= "To: {$to}\r\n";
$headers .= "From: {$name} <{$from}>\r\n";
$headers .= "Reply-To: <{$to}>\r\n";
$headers .= "Subject: {$subject}\r\n";
$headers .= "X-Mailer: PHP/".phpversion()."\r\n";

mail($from, $subject, $message, $headers);
 
}

?>
&#13;
&#13;
&#13;