LoRz

Saturday, September 20, 2008

 

Send email in Gmail with attachment using SwiftMailer


Sample Code

<?php

require_once "lib/Swift.php";
require_once "lib/Swift/Connection/SMTP.php";

$smtp =& new Swift_Connection_SMTP("smtp.gmail.com", Swift_Connection_SMTP::PORT_SECURE, Swift_Connection_SMTP::ENC_TLS);
$smtp->setUsername("username@gmail.com");
$smtp->setpassword("password");

$swift =& new Swift($smtp);

$message =& new Swift_Message("My subject");
$message->attach(new Swift_Message_Part("I have attached a file to this message!"));
$message->attach(new Swift_Message_Attachment(file_get_contents("test.jpg"), "test.jpg", "image/jpeg"));

$swift->send($message, "to@gmail.com", "username@gmail.com");

?>





<< Home

Archives

June 2008   July 2008   August 2008   September 2008   October 2008   November 2008   December 2008   January 2009   February 2009   March 2009   May 2009   July 2009   September 2009   October 2009   WEC 44 live stream   UFC 106 live stream

This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]