Truemag

  • Categories
    • Tips And Tricks
    • Internet
    • PHP
    • Javascript
    • CSharp
    • SQL Server
    • Linux
  • Lastest Videos
  • Our Demos
  • About
  • Contact
  • Home
  • Write With Us
  • Job Request
Home PHP PHPMailer Send Email With Attachments Via SMTP Authentication

PHPMailer Send Email With Attachments Via SMTP Authentication

Sending email is not just for some message you want your members/customers know. In some cases, you will need to send to them one or multiple documents such as: quote/sale report/user guide or whatever you want.

Again, PHPMailer is my choice for email transfer class and also with an Authenticated SMTP Server.

In the example below, I’ll send 2 attachments: 1 image and 1 text file. In your real situation, they could be PDF, DOC, XLS, PPT or any compressed files.

PHP send email with multiple attachments with PHPMailer with SMTP Authentication

<?php
	include "class.smtp.php";
	include "class.phpmailer.php";
 
	$Host = "mail.yourdomain.com";						// SMTP servers
	$Username = "your-smtp-username@yourdomain.com";	// SMTP password
	$Password = "your-smtp-password";					// SMTP username
 
 
	$From = "from-email@yourdomain.com";
	$FromName = "From Name";
 
	$To = "to-email@yourdomain.com";
	$ToName = "To Name";
 
	$Subject = "Hello there, you will receive some files";
	$Body = "This is a test email which includes attachment";
 
	$mail = new PHPMailer();
 
	$mail->IsSMTP();                 	// send via SMTP
	$mail->Host     = $Host; 
	$mail->SMTPAuth = true;     		// turn on SMTP authentication
	$mail->Username = $Username;  
	$mail->Password = $Password; 
 
	$mail->From     = $From;
	$mail->FromName = $FromName;
 
	$mail->AddAddress($To , $ToName);
 
	$mail->WordWrap = 50;				// set word wrap
	$mail->Priority = 1; 
	$mail->IsHTML(true);  
	$mail->Subject  =  $Subject;
	$mail->Body     =  $Body;
 
	$mail->AddAttachment("logo.jpg");      			// attachment
	$mail->AddAttachment("text-attachment.txt"); 	// attachment
 
	if(!$mail->Send())
	{
		echo "Mailer Error: " . $mail->ErrorInfo;
	}
	else
	{
		echo 'Message has been sent.';
	}
?>

Download source code above with PHPMailer include file and attachments for your testing. That example just send attachments to one recipient, if you want to send them to multiple recipients, let read more on How to send and CC to multiple recipients.

Jul 22, 2011 Hoan Huynh
PHP Send Email To Multiple Recipients And CC To Multiple Recipients With PHP MailerPHPMailer Send Email HTML Content With UTF-8 Encoding
You Might Also Like:
  • Send Email Via Gmail SMTP Authentication With PHPMailer
  • PHPMailer Send Email HTML Content With UTF-8 Encoding
  • PHP Send Email To Multiple Recipients And CC To Multiple Recipients With PHP Mailer
  • Sending Email With SMTP Authentication In WordPress
  • Simple PHP Code Send Email
  • How To Send Google Analytics Report To Emails
  • How To Track Website With Multiple Google Analytisc Accounts
  • Facebook Like Button And Recommend Button With fb:like, iframe and html5
  • Auto Convert Text To URL Link And MailTo Email Address With ASP.NET C#
  • Export Google Analytics Report To PDF In New Version
Hoan Huynh

Hoan Huynh is the founder and head of 4rapiddev.com. Reach him at hoan@4rapiddev.com

8 years ago PHPAddAttachment, IsSMTP, PHPMailer, SMTP, SMTP Authentication, SMTPAuth523
0
GooglePlus
0
Facebook
0
Twitter
0
Digg
0
Delicious
0
Stumbleupon
0
Linkedin
0
Pinterest
Most Viewed
PHP Download Image Or File From URL
18,765 views
Notepad Plus Plus Compare Plugin
How To Install Compare Text Plugin In Notepad Plus Plus
14,633 views
Microsoft SQL Server 2008 Attach Remove Log
Delete, Shrink, Eliminate Transaction Log .LDF File
13,366 views
JQuery Allow only numeric characters or only alphabet characters in textbox
10,933 views
C# Read Json From URL And Parse/Deserialize Json
7,503 views
4 Rapid Development is a central page that is targeted at newbie and professional programmers, database administrators, system admin, web masters and bloggers.
Recent Posts
  • Magento Fatal error: Unsupported operand types
  • Ionic bower the name contains uppercase letters
  • PHP Magento Get Manufacturer Name And ID From Magento Product ID
  • Know Simple Hacks To Systematize Media Library in WordPress
  • A handy guideline on adding custom menu item in WordPress admin
Categories
  • CSharp (45)
  • Facebook Graph API (19)
  • Google API (7)
  • Internet (87)
  • iPhone XCode (8)
  • Javascript (35)
  • Linux (26)
  • MySQL (16)
  • PHP (84)
  • Problem Issue Error (29)
  • Resources (32)
  • SQL Server (25)
  • Timeline (5)
  • Tips And Tricks (140)
EMAIL SUBSCRIPTION

Sign up for our newsletter to receive the latest news and event postings.

Recommended
  • CDN
  • Hosting
  • Premium Themes
  • VPS
2014 © 4 Rapid Development