Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. <?php
  2.  
  3. require_once 'path/to/SwiftMailer/lib/swift_required.php';
  4.  
  5. $transport = Swift_MailTransport::newInstance();
  6. # Create the Mailer using your created Transport
  7. $mailer = Swift_Mailer::newInstance($transport);
  8. # Create the message
  9. $msg = Swift_Message::newInstance();
  10. # Give the message a subject
  11. $msg->setSubject($_POST['subject']);
  12. # Set the From address with an associative array
  13. $msg->setFrom(array($_POST['sender_email'] => $_POST['sender_name']));
  14. # Give it a body
  15. $msg->setBody($_POST['message'], 'text/html');
  16.  
  17. $failedRecipients = array();
  18. $numSent = 0;
  19. $to = array(
  20. 'recipient_1@gmail.com',
  21. 'recipient_2@yahoo.com' => 'Recipient 2',
  22. 'recipient_3@hotmail.com',
  23. 'recipient_4@gmail.com' => 'Recipient 4',
  24. 'recipient_5@yahoo.com'
  25. );
  26.  
  27. foreach ($to as $address => $name) {
  28. if (is_int($address)) {
  29. $msg->setTo($name);
  30. } else {
  31. $msg->setTo(array($address => $name));
  32. }
  33.  
  34. $numSent += $mailer->send($msg, $failedRecipients);
  35. }
  36.  
  37. echo $numSent > 0 ? 'SUCCESS' : 'FAILURE';
  38.  
  39. ?>
  40.  
  41. $msg->setBody($_POST['message'], 'text/html');
  42.  
  43. $msg->setBody(stripslashes($_POST['message']), 'text/html');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement