Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. function sendmail($file,$mailto)
  2. {
  3. $mailer =& JFactory::getMailer();
  4. //var_dump($mailer); exit;
  5. $config =&JFactory::getConfig();
  6. $sender = array(
  7. $config->getValue( 'config.mailfrom' ),
  8. $config->getValue( 'config.fromname' )
  9. );
  10.  
  11. $mailer->setSender($sender);
  12.  
  13. $recipient = array($mailto);
  14. $mailer->addRecipient($recipient);
  15.  
  16. $body = "Your body stringnin double quotes if you want to parse the nnewlines etc";
  17. $mailer->setSubject('Your subject string');
  18. $mailer->setBody($body);
  19. // Optional file attached
  20.  
  21. $mailer->addAttachment(JPATH_BASE.DS.'CSV'.DS.$file);
  22.  
  23. $send =&$mailer->Send();
  24.  
  25. if ( $send !== true ) {
  26. echo 'Error sending email: ' . $send->message;
  27. } else {
  28. echo 'Mail sent';
  29. }
  30. }
  31.  
  32. $from="noreplay@gmail.com";//Please set Proper email id
  33. $fromname="noreplay";
  34. $to ='admin@gmail.com';
  35. // Set a you want send email to
  36. $subject = "Download";
  37. $message = "Thank you For Downloading";
  38. $attachment = JPATH_BASE.'/media/demo.pdf';
  39. // set a file path
  40. $res = JFactory::getMailer()->sendMail($from, $fromname, $to,$subject, $message,$mode=1,$cc = null, $bcc = null, $attachment);
  41. if($res)
  42. {
  43. $errormsg = "Mail Successfully Send";
  44. }
  45. else
  46. {
  47. $errormsg ="Mail Not Send";
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement