shahdhruvenn

PHPMailer Sending Email With Attachment

Sep 25th, 2012
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.96 KB | None | 0 0
  1. <?php
  2. require_once('../includes/phpmailer/class.phpmailer.php');
  3. $dirName = dirname(__FILE__);
  4. $filePath = "{$dirName}/templates/sample-financial-plan.pdf";
  5. $fileName = basename($filePath);
  6. $fileType = mime_content_type($filePath);
  7. $from_name="Getting You Rich Support Team";
  8. $to_name = "Dhruvenkumar Shah";
  9. $fname = "Dhruvenkumar";
  10. $lname = "Shah";
  11. $phone = "1234567890";
  12.  
  13. $body = <<<BODY
  14.     <html>
  15.         <head>
  16.         </head>
  17.         <body>
  18.             <div>
  19.                 $lname $fname $phone
  20.             </div>
  21.         </body>
  22.     </html>
  23. BODY;
  24.  
  25. $mail = new PHPMailer();
  26. $mail->From = $from;
  27. $mail->FromName = $from_name;
  28. $mail->AddAddress($to, $to_name);
  29. $mail->AddReplyTo($from, $from_name);
  30. $mail->AddAttachment($filePath);
  31. $mail->IsHTML(true);
  32. $mail->Body = $body;
  33. $mail->Subject = 'Your Sample Financial Plan';
  34.  
  35. if(!$mail->Send()) {
  36.   echo "Mailer Error: " . $mail->ErrorInfo;
  37. } else {
  38.   echo "Message sent!";
  39. }
  40.  
  41.  
  42. ?>
Advertisement
Add Comment
Please, Sign In to add comment