I want to send a mail using php through Gmail. I've seen many websites how to do it but I don't Understand how to do them. I am still stuck at the code I've written at first. Please help me how to connect my website (hosted on GoDaddy) to gmail account, and tell correct path to do that.
I am writing a code for clearer vision. In this php code, I am trying to add data in database and if the code works, the user should get an email from the company
if (isset($_POST['name']) && isset($_POST['mobile']) && isset($_POST['email']) && isset($_POST['practice']) && isset($_POST['date']) && isset($_POST['time']))
{
include "_credentials.php";
$name = $_POST['name'];
$mobile = $_POST['mobile'];
$email = $_POST['email'];
$practice = $_POST['practice'];
$date = $_POST['date'];
$time = $_POST['time'];
$sql = "INSERT INTO <database> (Name, Number, email, Practice, Time, Date) VALUES ('".$name."', ".$mobile.",'".$email."','".$practice."','".$date."','".$time."');";
if ($conn->query($sql) === TRUE) {
$to = $email;
$host = "ssl://smtp.gmail.com";
$subject = "Appointment Confirmation";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: abc@gmail.com' . "\r\n";
$txt = "Hello ".$name.",\n Your Appointment is booked with Doctor at Clinic on ".$date." at ".$time.".";
mail($to,$subject,$message,$headers);
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
}
Aucun commentaire:
Enregistrer un commentaire