Advertisement
Thiagocrepaldi

mail.php

Apr 12th, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.09 KB | None | 0 0
  1. <?php
  2.  
  3. if(isset($_POST['email'])) {
  4.     // Require the Swift Mailer library
  5.     require_once 'lib/swift_required.php';
  6.    
  7.     $transport = Swift_SmtpTransport::newInstance('mail.dominio.com.br', 25, 'tls' )
  8.       ->setUsername('mail@dominio.com.br')    
  9.       ->setPassword('54321')
  10.       ;
  11.  
  12.    
  13.     $mailer = Swift_Mailer::newInstance($transport);
  14.    
  15.    
  16.     // Creating the message text using fields sent through POST
  17.    
  18.     foreach ($_POST as $key => $value)
  19.         $messageText .= ucfirst($key).": ".$value."\n\n";
  20.    
  21.    
  22.    
  23.    
  24.     // You can change "A message from Pivot Template Form" to your own subject if you want.
  25.     $message = Swift_Message::newInstance('Coronel David - Mensagem enviado pelo site')
  26.       ->setFrom(array($_POST['email'] => $_POST['name']))
  27.       ->setTo(array('contato@dominio.com.br' => 'Coronel David'))->setBody($messageText);
  28. //                           ^                    ^
  29. //       Your email address_/          Your name_/
  30.  
  31.      
  32.  
  33.     // Send the message or catch an error if it occurs.
  34.     try{
  35.         echo($mailer->send($message));
  36.     }
  37.     catch(Exception $e){
  38.         echo($e->getMessage());
  39.     }
  40.     exit;
  41. }
  42.  
  43. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement