I am sending emails successfully using following code. But now I want to attach a text file (example: test.txt) with email. Any Idea?
require_once "Mail.php";
$from = "Usman <[email protected]>";
$to = "Naveed <[email protected]>";
$subject = "subject";
$body = "";
$host = "smtp.gmail.com";
$username = "username";
$password = "password";
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory( 'smtp', array('host' => $host,
'auth' => true,
'username' => $username,
'password' => $password ) );
$mail = $smtp->send( $to, $headers, $body );
if ( PEAR::isError($mail) ) {
echo( "<p>" . $mail->getMessage() . "</p>" );
} else {
echo( "<p>Message successfully sent!</p>" );
}