Advertisement
Arxkanite

PHP Mail Attachment

Jul 17th, 2014
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.95 KB | None | 0 0
  1. <?php
  2.  
  3. // Include the mailer
  4. require_once "phpmailer/class.phpmailer.php";
  5.  
  6. $mail = new PHPMailer(true);
  7.  
  8. $mail->IsSMTP();
  9. $mail->SMTPDebug  = 2;
  10. $mail->SMTPAuth   = true;
  11.  
  12. $message = "Send email with <strong style='color: #ff0000'>PHPMailer</strong> from my SMTP account.<br />";
  13.  
  14. try {
  15.    
  16.     // First we should get the file
  17.     // This is the folder you should store the uploaded files in temporarily while they are being attached. "Keep it Secret, Keep it Safe."
  18.     $target_path = "uploads/"
  19.    
  20.     $target_path = $target_path . basename($_FILES['kool_name_here']['name']);
  21.     if ( move_uploaded_file($_FILES['kool_name_here']['tmp_name'], $target_path)) {
  22.         // Attach A file!
  23.         $mail->AddAttachment(basename($target_path . $_FILES['uploadedfile']['name']))
  24.     }
  25.        
  26.    
  27.     //SMTP server
  28.     $mail->Host = "SMTP host";
  29.     //SMTP port, for example, 25, 587, 2525, ...
  30.     $mail->Port = 587;
  31.     //SMTP account username
  32.     $mail->Username = "youraccount@SMTP host";
  33.     //SMTP account password
  34.     $mail->Password = "yourpassword";
  35.  
  36.     //mail from
  37.     $mail->SetFrom($mail->Username, "your name");
  38.     //replay to
  39.     $mail->AddReplyTo($mail->Username, "your name");
  40.  
  41.     $recipient_address = "recipient@somedomain.com";
  42.     $recipient_name = "recipient name";
  43.     $mail->AddAddress($recipient_address, $recipient_name);
  44.  
  45.     //adding carbon copy CC recipients
  46.     //$mail->AddCC("recipient1@domain.com", "First Person");  
  47.  
  48.     //adding blind carbon copy BCC recipients
  49.     //$mailer->AddBCC("recipient1@domain.com", "First Person");
  50.  
  51.     $mail->Subject = "Test email sending";  
  52.     //create an alternate automatically
  53.     //$mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
  54.    
  55.    
  56.     // Attach the message as HTML. Remember HTML for emails is super lame and not standard.
  57.     $mail->MsgHTML($message);
  58.  
  59.     $mail->Send();
  60.  
  61.     echo "<br />Message Sent OK!";
  62.  
  63. } catch (phpmailerException $e)
  64. {
  65.     echo $e->errorMessage();
  66.  
  67. } catch (Exception $e)
  68. {
  69.     echo $e->getMessage();
  70. }
  71.  
  72.  
  73. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement