Advertisement
Guest User

Untitled

a guest
Dec 11th, 2016
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. <?php
  2. function sendMail($mailFrom, $replyTo, $mailTo, $ccTo, $mailSubject, $mailContent, $mailTemplate)
  3. {
  4. // Create a new PHPMailer instance
  5. $mail = new PHPMailer();
  6. // Tell PHPMailer to use SMTP
  7. $mail->isSMTP();
  8. // Enable SMTP debugging
  9. // 0 = off (for production use)
  10. // 1 = client messages
  11. // 2 = client and server messages
  12. $mail->SMTPDebug = 0;
  13. //Ask for HTML-friendly debug output
  14. $mail->Debugoutput = 'html';
  15. // Set the hostname of the mail server
  16. $mail->Host = "hostname of your mail server";
  17. // Set the SMTP port number - likely to be 25, 465 or 587
  18. $mail->Port = 25;
  19. // Whether to use SMTP authentication
  20. $mail->SMTPAuth = true;
  21. // Secure transfer enabled REQUIRED for GMail
  22. $mail->SMTPSecure = 'ssl';
  23. // Username to use for SMTP authentication
  24. $mail->Username = "username for sending emails";
  25. // Password to use for SMTP authentication
  26. $mail->Password = "password for the above username";
  27. // Set who the message is to be sent from
  28. $mail->setFrom($mailFrom['address'], $mailFrom['name']);
  29. // If the reply to values are present
  30. if (isset($replyTo['address']) && isset($replyTo['name'])) {
  31. // Set an alternative reply-to address
  32. $mail->addReplyTo($replyTo['address'], $replyTo['name']);
  33. }
  34. // Set who the message is to be sent to
  35. $mail->addAddress($mailTo['address'], $mailTo['name']);
  36. // Set who the message is to be cc'd to
  37. if (count($ccTo) > 0) {
  38. foreach ($ccTo as $ccToKey=>$ccToValues) {
  39. $mail->addCC($ccToValues['address'], $ccToValues['name']);
  40. }
  41. }
  42. // If an attachment exists
  43. if (isset($mailContent['attachment'])) {
  44. // Add it to the email
  45. $mail->addAttachment($mailContent['attachment']);
  46. }
  47. // Set the subject line
  48. $mail->Subject = $mailSubject;
  49. // Define mail message <----------- NB!!!!!!!!
  50. require_once pS . '/mailers/layouts/'.$mailTemplate.'.email.php';
  51. // Convert HTML into a basic plain-text alternative body
  52. $mail->msgHTML($mailMessage);
  53. // Define basic mail message <----------- NB!!!!!!!!
  54. require_once pS . '/mailers/layouts/'.$mailTemplate.'.basic.php';
  55. // Send the message, check for errors
  56. if (!$mail->send()) {
  57. return array=>(false, "Mailer Error: " . $mail->ErrorInfo);
  58. } else {
  59. return array=>(true);
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement