0

How to email them after they fill out the form I created, for example

          <form class="form-horizontal" action="" method="post">



      <div class="form-group">
           <input type="text" class="form-control"  
            id="" value="" name="" placeholder="Name">
      </div>

      <div class="form-group">
           <input type="email" class="form-control"  
               id="" value=""  
               placeholder="Email">
      </div>

      <div class="form-group">
       <textarea class="form-control" rows="3" placeholder="" 
        Required autofocus></textarea>
      </div>

        <div class="form-group">
          <input type="submit" name="submit" class="btn btn-info 
           btn-block" value="submit">
        </div>
</form>

For example, I input this form. After that I can directly email from admin. And i check my email, i get email "thank you already input".

thanks.

  • Unimaginable. I've been watching tutorials how to send email, but have not yet to receive email tutorials after input –  May 09 '17 at 04:50
  • 1
    I just searched "php email form" and found _loads_ of tutorials. Handling forms is PHP 101. SO isn't a free coding service. We will gladly help you when you get stuck with your _existing_ code. but we won't write it for you. – M. Eriksson May 09 '17 at 04:54
  • There's a default `mail()` function http://php.net/mail - but you should look into SwiftMailer or PHPMailer. That should get you started. If you're on localhost, be sure to install and run a mailserver too. – Qirel May 09 '17 at 04:54
  • Try following this tutorial https://www.formget.com/send-email-via-gmail-smtp-server-in-php/ – gobliggg May 09 '17 at 04:57

2 Answers2

0

You can use PHPMailer class at https://github.com/PHPMailer/PHPMailer . It allows you to use the mail function or use an smtp server transparently. It also handles HTML based emails and attachments so you don't have to write your own implementation. Here is an example from the page above:

<?php
require 'PHPMailerAutoload.php';

$mail = new PHPMailer;

$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'smtp1.example.com;smtp2.example.com';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'user@example.com';                 // SMTP username
$mail->Password = 'secret';                           // SMTP password
$mail->SMTPSecure = 'tls';                            // Enable encryption, 'ssl' also accepted

$mail->From = 'from@example.com';
$mail->FromName = 'Mailer';
$mail->addAddress('joe@example.net', 'Joe User');     // Add a recipient
$mail->addAddress('ellen@example.com');               // Name is optional
$mail->addReplyTo('info@example.com', 'Information');
$mail->addCC('cc@example.com');
$mail->addBCC('bcc@example.com');

$mail->WordWrap = 50;                                 // Set word wrap to 50 characters
$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
$mail->isHTML(true);                                  // Set email format to HTML

$mail->Subject = 'Here is the subject';
$mail->Body    = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';
}
Mahfuzur Rahman
  • 1,497
  • 18
  • 23
-2

I suggest u use PHP MAILER.

  1. Create a Gmail account and set password application (tutorial)
  2. Use your Gmail u create before use PHP MAILER, remember use password application You can see example code here
Nguyen Toan
  • 34
  • 1
  • 8