Last active
June 10, 2024 14:45
-
-
Save daveh/1164348fe21a6e7363d28c7b94c9eb3f to your computer and use it in GitHub Desktop.
Send email with PHP (code to accompany https://youtu.be/fIYyemqKR58)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Contact</title> | |
<meta charset="UTF-8"> | |
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/water.css@2/out/water.css"> | |
</head> | |
<body> | |
<h1>Contact</h1> | |
<form method="post" action="send-email.php"> | |
<label for="name">Name</label> | |
<input type="text" name="name" id="name" required> | |
<label for="email">email</label> | |
<input type="email" name="email" id="email" required> | |
<label for="subject">Subject</label> | |
<input type="text" name="subject" id="subject" required> | |
<label for="message">Message</label> | |
<textarea name="message" id="message" required></textarea> | |
<br> | |
<button>Send</button> | |
</form> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$name = $_POST["name"]; | |
$email = $_POST["email"]; | |
$subject = $_POST["subject"]; | |
$message = $_POST["message"]; | |
require "vendor/autoload.php"; | |
use PHPMailer\PHPMailer\PHPMailer; | |
use PHPMailer\PHPMailer\SMTP; | |
$mail = new PHPMailer(true); | |
// $mail->SMTPDebug = SMTP::DEBUG_SERVER; | |
$mail->isSMTP(); | |
$mail->SMTPAuth = true; | |
$mail->Host = "smtp.example.com"; | |
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; | |
$mail->Port = 587; | |
$mail->Username = "you@example.com"; | |
$mail->Password = "password"; | |
$mail->setFrom($email, $name); | |
$mail->addAddress("dave@example.com", "Dave"); | |
$mail->Subject = $subject; | |
$mail->Body = $message; | |
$mail->send(); | |
header("Location: sent.html"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Contact</title> | |
<meta charset="UTF-8"> | |
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/water.css@2/out/water.css"> | |
</head> | |
<body> | |
<h1>Contact</h1> | |
<p>Thank you for your message.</p> | |
</body> | |
</html> |
can u give me your personal mail ?
for asking a doubt regarding your SMTP video ??
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@Shafeeqvv You need to be able to run PHP - the simplest way to do this is to install something like XAMPP and put the scripts in the root folder, then load them from there.