-
-
Save daveh/1164348fe21a6e7363d28c7b94c9eb3f to your computer and use it in GitHub Desktop.
<!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> |
<?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 = "[email protected]"; | |
$mail->Password = "password"; | |
$mail->setFrom($email, $name); | |
$mail->addAddress("[email protected]", "Dave"); | |
$mail->Subject = $subject; | |
$mail->Body = $message; | |
$mail->send(); | |
header("Location: sent.html"); |
<!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> |
@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.
can u give me your personal mail ?
for asking a doubt regarding your SMTP video ??
Hi Dave, I have a neubie q for you: No closing PHP ?> after line 35 of send-emai.php. HTTP ERROR 500
I have a hosted site on Ggodaddy.
@charlesdarwall1 If a file just contains PHP, it's not necessary to include the closing PHP tag. In fact it's recommended not to, as you can introduce hard to find whitespace.
If you're getting a 500 error, this means that PHP isn't configured to show you the actual details of the error. Try adding this to the top of your script:
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
Then the error message will tell you exactly what the error is and what line it's on.
Fatal error: Uncaught PHPMailer\PHPMailer\Exception: SMTP Error: Could not connect to SMTP host. Failed to connect to server in C:\xampp\htdocs\form\vendor\phpmailer\phpmailer\src\PHPMailer.php:2282 Stack trace: #0 C:\xampp\htdocs\form\vendor\phpmailer\phpmailer\src\PHPMailer.php(2058): PHPMailer\PHPMailer\PHPMailer->smtpConnect(Array) #1 C:\xampp\htdocs\form\vendor\phpmailer\phpmailer\src\PHPMailer.php(1687): PHPMailer\PHPMailer\PHPMailer->smtpSend('Date: Thu, 28 N...', 'ggggggggggggg\r\n') #2 C:\xampp\htdocs\form\vendor\phpmailer\phpmailer\src\PHPMailer.php(1521): PHPMailer\PHPMailer\PHPMailer->postSend() #3 C:\xampp\htdocs\form\send-email.php(33): PHPMailer\PHPMailer\PHPMailer->send() #4 {main} thrown in C:\xampp\htdocs\form\vendor\phpmailer\phpmailer\src\PHPMailer.php on line 2282 i meet with this error what i do
what I do about those error
@Niyonkuru-olivier It looks like your SMTP server address is either incorrect or the server is unreachable - check the address or try a different SMTP server
How I check those SMTP server address
this is my code. helps me
smtp.example.com is not a valid SMTP server, it's just an example. You need to use one you have access to (e.g. smtp.google.com if you have a Gmail account etc.)
hey Daveh can we do this work without hosting the site? i did this work on sublime text