Advertisement
Guest User

Untitled

a guest
May 18th, 2018
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.86 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: Victo
  5.  * Date: 2018-05-14
  6.  * Time: 17:10
  7.  */
  8.  
  9. require 'PHPMailerAutoload.php';
  10. $mail = new PHPMailer;
  11.  
  12. $from = $_POST['mailFrom'];
  13. $to = $_POST['mailTo'];
  14. $subject = $_POST['mailSubject'];
  15. $message = $_POST['messageMail'] . 'Observera! Detta meddelande är skickat från ett formulär på Internet och avsändaren kan vara felaktig!';
  16. $password = $_POST['passwordInput'];
  17. if (valid_email($from) == false){
  18.     echo 'Sender email not right';
  19.     echo file_get_contents('5.1.html');
  20. }elseif (!valid_email($to)) {
  21.     echo 'reciver email not right';
  22.     echo file_get_contents('5.1.html');
  23. }elseif($password!== '1234') {
  24.     echo 'Password not right';
  25.     echo file_get_contents('5.1.html');
  26. }
  27. else {
  28.     $mail = new PHPMailer(true);
  29.     $headers = array(
  30.         'From' => $from,
  31.         'To' => $to,
  32.         'Subject' => $subject
  33.     );
  34.  
  35.  
  36.     $mail->SMPTDebug = 2;
  37.     $mail->IsSMTP();
  38.     $mail->Mailer = "smtp";
  39.     $mail->Host = 'smtp.gmail.com';
  40.     $mail->Port = 465;                                      //Kan även använda porten 587
  41.     $mail->SMTPAuth = true;
  42.     $mail->Username = 'Victor.Jendelheim@gmail.com';                  //Byta ut till eget id
  43.     $mail->Password = 'tgcmxzqw9';                   //Byta ut till eget lösenord
  44.     $mail->SMTPSecure = 'ssl';
  45.     $mail->setFrom($from);
  46.     $mail->addAddress($to);
  47.     $mail->isHTML(true);
  48.     $mail->Subject = $subject;
  49.     $mail->Body = $message;
  50.  
  51.  
  52.     if (!$mail->send()) {
  53.         echo "Mailer Error: " . $mail->ErrorInfo;
  54.     } else {
  55.         echo "Message sent!";
  56.     }
  57. }
  58. function valid_email($email) {
  59.     if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
  60.         echo("$email is a valid email address");
  61.         return true;
  62.     } else {
  63.         echo("$email is not a valid email address");
  64.         return false;
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement