Advertisement
AviEzerzer

Untitled

Apr 18th, 2019
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.74 KB | None | 0 0
  1. <?php
  2. use PHPMailer\PHPMailer\Exception;
  3. use PHPMailer\PHPMailer\PHPMailer;
  4.  
  5. require '/vendor/autoload.php';
  6.  
  7. $mail = new PHPMailer(true);
  8.  
  9. $name = test_input($_POST["name"]);
  10. $email = test_input($_POST["email"]);
  11. $phone = test_input($_POST["phone"]);
  12. $subject = test_input($_POST["subject"]);
  13. $message = test_input($_POST["message"]);
  14.  
  15. //add your email details here!
  16. $mySmtpHost = '';
  17. $myEmail = '';
  18. $myemailPassword = '';
  19. $myPhone = '';
  20.  
  21. $Body = "<html>
  22. <body>
  23.    <h2>You have a message from www.fatmaardabicaz.av.tr website user</h2>
  24.    <hr>
  25.    <p>Isim:<br>`.$name.`</p>
  26.    <p>E-mail:<br>`.$myEmail.`</p>
  27.    <p>Telefon:<br>`.$myPhone.`</p>
  28.    <p>Mesaj:<br>`.$message.`</p>
  29. </body>
  30. </html>";
  31.  
  32. try {
  33.     $mail->isSMTP();
  34.     $mail->SMTPDebug = 2; // Enable verbose debug output
  35.     $mail->Host = $mySmtpHost;
  36.     $mail->SMTPAuth = true;
  37.     $mail->Username = $myEmail;
  38.     $mail->Password = $myemailPassword;
  39.     $mail->SMTPSecure = 'tls';
  40.     $mail->Port = 587;
  41.  
  42.     // $headers = "From: " . $name . " <" . $email . ">\r\n";
  43.     // $headers = "MIME-Version: 1.0\r\n";
  44.     // $headers = "Content-type: text/html; charset-utf-8";
  45.  
  46.     // $name = $_POST['name'];
  47.     // $email = $_POST['email'];
  48.     // $phone = $_POST['phone'];
  49.     // $subject = $_POST['subject'];
  50.     // $message = $_POST['message'];
  51.     // $to = "mymailaddress.com";
  52.  
  53.     //sent from (your email,your subject)
  54.     $mail->setFrom($myEmail, $subject);
  55.     //who you are sending the email to
  56.     $mail->addAddress($email, $name); // Name is optional
  57.     $mail->addReplyTo($myEmail, 'Information');
  58.     // Content
  59.     $mail->isHTML(true); // Set email format to HTML
  60.     $mail->Subject = 'Here is the subject';
  61.     // $mail->Body = '<html>
  62.     //            <body>
  63.     //                <h2>You have a message from www.fatmaardabicaz.av.tr website user</h2>
  64.     //                <hr>
  65.     //                <p>Isim:<br>`.$name.`</p>
  66.     //                <p>E-mail:<br>`.$email.`</p>
  67.     //                <p>Telefon:<br>`.$phone.`</p>
  68.     //                <p>Mesaj:<br>`.$message.`</p>
  69.     //            </body>
  70.     //        </html>';
  71.     // $txt = " You have a message from: " . $name . ".\n\n" . $message;
  72.  
  73.     // Content
  74.     $mail->isHTML(true); // Set email format to HTML
  75.     $mail->Subject = 'Here is the subject';
  76.     $mail->Body = $message;
  77.  
  78.     $mail->setLanguage('tr', 'vendor/phpmailer/phpmailer/language/phpmailer.lang-tr.php');
  79.     $mail->send();
  80.     echo 'Message has been sent';
  81. } catch (Exception $e) {
  82.     echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
  83. }
  84.  
  85. function test_input($data)
  86. {
  87.     $data = trim($data);
  88.     $data = stripslashes($data);
  89.     $data = htmlspecialchars($data);
  90.     return $data;
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement