Send mail with Swift Mailer


/ Published in: PHP
Save to your folder(s)

Script to send mails with Swift Mailer


Copy this code and paste it in your HTML
  1. <?php
  2. require_once 'lib/swift_required.php';
  3. include "conexion.php";
  4.  
  5. $correo = $_POST['correo']; //Mail Receiver
  6.  
  7. //Create the Transport
  8. $transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 25)
  9. ->setUsername('[email protected]')
  10. ->setPassword('password')
  11. ;
  12.  
  13. /*
  14. You could alternatively use a different transport such as Sendmail or Mail:
  15.  
  16. //Sendmail
  17. $transport = Swift_SendmailTransport::newInstance('/usr/sbin/sendmail -bs');
  18.  
  19. //Mail
  20. $transport = Swift_MailTransport::newInstance();
  21. */
  22.  
  23. //Create the Mailer using your created Transport
  24. $mailer = Swift_Mailer::newInstance($transport);
  25.  
  26. //Create a message
  27. $message = Swift_Message::newInstance('Banco de Ideas')
  28. ->setFrom('[email protected]')
  29. ->setTo($correo) // ->setTo('[email protected]')
  30. ->setBody('Your message...')
  31. ;
  32.  
  33. //Send the message
  34. $result = $mailer->send($message);
  35.  
  36. /*
  37. You can alternatively use batchSend() to send the message
  38.  
  39. $result = $mailer->batchSend($message);
  40. */
  41.  
  42. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.