Advertisement
Guest User

Untitled

a guest
Apr 19th, 2017
570
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. require 'Classes/mail/PHPMailerAutoload.php';
  2.  
  3. $mail = new PHPMailer;
  4.  
  5. $recipient = $_POST['email_address'];
  6. $recipient = preg_replace('/s+/', '', $recipient);
  7. $recipient = trim($recipient, ';');
  8.  
  9. $recipient_array = explode(';', $recipient);
  10.  
  11. $subject = $_POST['email_subject'];
  12. $body = nl2br($_POST['email_message']);
  13.  
  14. $footer = '<br />
  15. <table id="email_footer">
  16. <tr>
  17. <td>
  18. EMAIL SIGNATURE
  19. </td>
  20. </tr>
  21. <tr>
  22. <td>
  23. <hr />
  24. FOOTER IMAGE
  25. <hr />
  26. </td>
  27. </tr>
  28. <tr>
  29. <td style="font-size:15px">
  30. ADDRESS
  31. </td>
  32. </tr>
  33. </table>';
  34.  
  35. $attachment = 'pdf/' . $_POST['attachment'];
  36.  
  37. $mail->isSMTP(); // Set mailer to use SMTP
  38. $mail->Host = 'localhost'; // Specify main and backup SMTP servers
  39. $mail->SMTPAuth = true; // Enable SMTP authentication
  40. $mail->Username = 'webmaster@example.com'; // SMTP username
  41. $mail->Password = 'password123'; // SMTP password
  42. $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
  43. $mail->Port = "25"; // TCP port to connect to
  44.  
  45. $mail->SMTPOptions = array(
  46. 'ssl' => array(
  47. 'verify_peer' => false,
  48. 'verify_peer_name' => false,
  49. 'allow_self_signed' => true
  50. )
  51. );
  52.  
  53. $mail->setFrom('webmaster@example.com', 'Business Name');
  54. $mail->addReplyTo('webmaster@example.com', 'Business Name');
  55.  
  56. for ( $i = 0; $i < count( $recipient_array ); $i++ )
  57. {
  58. $mail->addAddress( $recipient_array[$i] );
  59. }
  60.  
  61. $mail->addAddress('example@zoho.com'); // Forwards to local email for records (cannot send email to own server [workaround])
  62.  
  63. $mail->Subject = $subject; // Subject
  64. $mail->Body = $body . '<br />' . $footer; // Body of email
  65. $mail->AddAttachment( $attachment, 'purchase-order.pdf' ); // Attach a file
  66.  
  67. $mail->isHTML(true); // Set email format to HTML
  68.  
  69. if( !$mail->send() )
  70. {
  71. echo 'Message could not be sent.<br />';
  72. echo 'Mailer Error: ' . $mail->ErrorInfo;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement