How the php form is submitted to mysql and sent to the specified mailbox at the same time

now you can insert data into mysql by submitting the form through html.

the php code is as follows

  <?php 
    session_start(); 
    $username=$_REQUEST["username"]; 
    $phone=$_REQUEST["phone"]; 
    $datetime=$_REQUEST["datetime"]; 
    $con=mysql_connect("localhost","root","root"); 
    if (!$con) { 
      die("".$mysql_error()); 
    } 
    mysql_select_db("user_info",$con); 
    $dbusername=null; 
    $dbphone=null; 
    $result=mysql_query("select * from user_info where phone ="{$phone}" and isdelete =0;"); 
    while ($row=mysql_fetch_array($result)) { 
      $dbusername=$row["username"]; 
      $dbphone=$row["phone"]; 
    } 

    if(!is_null($dbphone)){ 
  ?> 
  <script type="text/javascript"> 
    alert(""); 
    window.location.href="index.html"; 
  </script>  
  <?php  
    } 
    
    mysql_query("insert into user_info (username,phone,datetime) values("{$username}","{$phone}",now())") or die("".mysql_error()) ; 
    mysql_close($con); 
  ?> 
  <script type="text/javascript"> 
    alert(""); 
    window.location.href="index.html"; 
  </script> 

on this basis, how to send the contents inserted into the database to the specified mailbox at the same time? Is there a case reference?

Mar.05,2021

  1. you can use the php mail extension. Call
after adding the relevant configuration according to the manual

http://php.net/manual/zh/mail.

$to = "someone@example.com";         // 
$subject = "";                // 
$message = "Hello! ";  // 
$from = "someonelse@example.com";   // 
$headers = "From:" . $from;         // 
mail($to,$subject,$message,$headers);
echo "";

2. You can also use phpmailer to send
https://github.com/PHPMailer/.

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

//Load Composer's autoloader
require 'vendor/autoload.php';

$mail = new PHPMailer(true);                              // Passing `true` enables exceptions
try {
    //Server settings
    $mail->SMTPDebug = 2;                                 // Enable verbose debug output
    $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 TLS encryption, `ssl` also accepted
    $mail->Port = 587;                                    // TCP port to connect to

    //Recipients
    $mail->setFrom('from@example.com', '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');

    //Attachments
    $mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
    $mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name

    //Content
    $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';

    $mail->send();
    echo 'Message has been sent';
} catch (Exception $e) {
    echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}

composer introduces phpmailer/phpmailer dependency phpmailer/phpmailer


that's what I did, but it was slow to send, resulting in a long wait to submit the form.


send mail into an asynchronous queue for processing


headfirst php&mysql has the same item


I think it's more convenient to send api directly by mail from a big factory

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1ea4e48-47ae5.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1ea4e48-47ae5.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?