Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $to = "<to>"; // this is your email address
- $from = $_POST['email']; // this is the sender's email address
- $name = $_POST['name']; // this is the sender's name
- $email = $_POST['email']; // this is the sender's email address
- $message = $_POST['message']; // this is the sender's message
- $emailmessage = "Email: " . $from . "<br />" . "Name: " . $name . "<br />" . "Message: " . $message; // this is the merged message
- use PHPMailer\PHPMailer\PHPMailer;
- use PHPMailer\PHPMailer\Exception;
- require 'src/Exception.php';
- require 'src/PHPMailer.php';
- require 'src/SMTP.php';
- $mail = new PHPMailer(true);
- try {
- //Server settings
- // Enable verbose debug output
- $mail->SMTPDebug = 0;
- // Set mailer to use SMTP
- $mail->isSMTP();
- // Specify main and backup SMTP servers seperated by a comma
- $mail->Host = '';
- // SMTP authentication
- $mail->SMTPAuth = true;
- // SMTP username
- $mail->Username = '';
- // SMTP password
- $mail->Password = '';
- // Enable encryption: SSL or TLS
- $mail->SMTPSecure = '';
- // SMTP Server port
- $mail->Port = 465;
- //Recipients
- // Message sender
- $mail->setFrom($from, 'name of sender');
- // Add a recipient
- $mail->addAddress($to, 'name of recipient');
- //Content
- // Set email format to HTML
- $mail->isHTML(true);
- // Set email subject
- $mail->Subject = 'A message from your website';
- // Set email body
- $mail->Body = $emailmessage;
- $mail->send();
- echo 'Message has been sent';
- } catch (Exception $e) {
- echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
- }
- ?>
Advertisement