nickjedl

mail.php

Jan 15th, 2018
2,973
0
Never
13
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.59 KB | None | 0 0
  1. <?php
  2. $to = "<to>"; // this is your email address
  3. $from = $_POST['email']; // this is the sender's email address
  4. $name = $_POST['name']; // this is the sender's name
  5. $email = $_POST['email']; // this is the sender's email address
  6. $message = $_POST['message']; // this is the sender's message
  7. $emailmessage = "Email: " . $from . "<br />" . "Name: " . $name . "<br />" . "Message: " . $message; // this is the merged message
  8.  
  9. use PHPMailer\PHPMailer\PHPMailer;
  10. use PHPMailer\PHPMailer\Exception;
  11.  
  12. require 'src/Exception.php';
  13. require 'src/PHPMailer.php';
  14. require 'src/SMTP.php';
  15.  
  16. $mail = new PHPMailer(true);
  17. try {
  18.     //Server settings
  19.     // Enable verbose debug output
  20.     $mail->SMTPDebug = 0;
  21.     // Set mailer to use SMTP
  22.     $mail->isSMTP();
  23.     // Specify main and backup SMTP servers seperated by a comma
  24.     $mail->Host = '';
  25.     // SMTP authentication
  26.     $mail->SMTPAuth = true;
  27.     // SMTP username
  28.     $mail->Username = '';
  29.     // SMTP password
  30.     $mail->Password = '';
  31.     // Enable encryption: SSL or TLS
  32.     $mail->SMTPSecure = '';
  33.     // SMTP Server port
  34.     $mail->Port = 465;
  35.  
  36.     //Recipients
  37.     // Message sender
  38.     $mail->setFrom($from, 'name of sender');
  39.     // Add a recipient
  40.     $mail->addAddress($to, 'name of recipient');
  41.  
  42.     //Content
  43.     // Set email format to HTML
  44.     $mail->isHTML(true);
  45.     // Set email subject   
  46.     $mail->Subject = 'A message from your website';  
  47.     // Set email body
  48.     $mail->Body = $emailmessage;
  49.  
  50.     $mail->send();
  51.     echo 'Message has been sent';
  52. } catch (Exception $e) {
  53.     echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
  54. }
  55.  
  56. ?>
Advertisement
Comments
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
Add Comment
Please, Sign In to add comment