I am new to php and currently doing a project
I stored data in database by using a form.
I have a mail function, when on clicking the submit button, a mail is send to reputed email id. I am using phpmailer library.
This is my mail function
class mail
{
public function sendMail(){
require 'vendor/autoload.php';
$mail = new PHPMailer(); // Passing `true` enables exceptions or null without exception
//Server settings
$mail->SMTPDebug = 0; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'xyz@gmail.com'; // SMTP username
$mail->Password = 'xyz123'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
//Recipients
$mail->setFrom('xyz@gmail.com', 'xyz');
$mail->addAddress('abc@gmail.com', 'abc');
$mail->addCC('zxc@gmail.com');
//Attachments
$mail->addAttachment('lob.png', 'sample.png'); // Add attachments
// Optional name
//Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Report';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
if (!$mail->send()) {
return "Error sending message" . $mail->ErrorInfo;
} else {
return "Message sent!";
}
}
}
This is my code to store data into database as send.php
if(isset($_POST['submit'])){
$name = $_POST['name'];
$age = $_POST['age'];
$quality = $_POST['quality'];
$sql = "INSERT INTO user(name,age,quality) VALUES('$name','$age','$quality')";
}
This is my html form
<form class="quality" method="POST" action="send.php">
<label for="name">Name</label>
<input type = "text" class = "form-quality" name="name" value="" / >
<label for="age">Age</label>
<input type="text" class ="form-quality" name="age" value="" / >
<label for="quality">Quality</label>
<input type="ratio" class ="form-quality" name="quality" value="E" / >
<input type="ratio" class ="form-quality" name="quality" value="P" / >
</form>
1) How to get the data's from database ?
2) In mail function previously sending emails to one or two id's, but i need as when i select "value = E" from ratio button , it should send to one email and if i select "value= P" it should send to another email based on user selected values stored in the database
Anyone with a best reply will be much more needed help for me