IronFace
IronFace

Reputation: 9

how can i send php mail with html contact form

I am currently trying to send an HTML contact form or the contents of it using php mail () function. Just hang up and ask for help.

How can I e.g. Your entered text and the email address specified in the contact form via PHP?

So my code looks currently and it works .. Only I do not know how I the data entered and send it with ..

HTML CODE:

          <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 CODE:

<?php
          $empfaenger = "[email protected]";
          $betreff = "Mail Function";
          $from = "From: Max Reimers <[email protected]>";
          $text = "Email Email Email Email Text Text Text";

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

Upvotes: 0

Views: 3623

Answers (1)

Adlivetech
Adlivetech

Reputation: 21

Here is Code:

<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 = '[email protected]'; 
    $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);
 
}

?>

Upvotes: 2

Related Questions