Complete example snippets

Swift Mailer is a fantastic library for sending email with php. Discuss this library or ask any questions about it here.

Moderators: Chris Corbyn, General Moderators

Post Reply
Joehoch
Forum Newbie
Posts: 5
Joined: Tue Jan 20, 2009 9:08 pm

Complete example snippets

Post by Joehoch »

I stumbled across Swift while looking for a quick and easy way to send mail from my web site. I really hadn't planned on becoming an email expert, just some essential communications with my clients.

Installed swift just like it said and ran the smoke test. Perfect, did everything I needed it to do.

Constructing a usable script, however, isn't quite as apparent as it seems to be. The examples are delivered across a series of categories and I am sure quite clear for the experienced. What I am hoping I can accomplish here is get a clear functioning (and complete) example for my needs so I can move on.

My situation is this:

I need to send to a client, I have.

$to = "to";
$from = "me";
$subject = "whatever";
$message = "what I have to say";

I need to authenticate to a remote smtp server:

$server = "server.domain.com";
$user = "my account name";
$upass= "my account pass";

My needs are simple, but I am not making a lot of sense out of the examples. Does anyone have or can point me to a functioning example for the information I have and how to get the thing out the door?

The only other variation I would have at some point is the need to send to multiple receivers on my active list (doesn't happen much) - but I suspect I can simply loop it?

Any help would be appreciated.
Last edited by Joehoch on Tue Jan 20, 2009 9:30 pm, edited 1 time in total.
Joehoch
Forum Newbie
Posts: 5
Joined: Tue Jan 20, 2009 9:08 pm

Re: Complete example snippets

Post by Joehoch »

Oh incidentally..

I am on a windows box - using php5 and swift 3.3.3 for php5
Joehoch
Forum Newbie
Posts: 5
Joined: Tue Jan 20, 2009 9:08 pm

Re: Complete example snippets

Post by Joehoch »

Nobody?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Complete example snippets

Post by Chris Corbyn »

[EDIT | Apologies, I mixed your thread up with somebody elses]

You're asking for something very specific and basically Swift Mailer isn't designed in the way that mean there's a set way to do something.

That said, I have planned chapters in the documentation for the new version which will include both tutorials and usage patterns.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Complete example snippets

Post by Chris Corbyn »

Without having somebody build the entire thing for you, could you perhaps share what it is you're getting stuck on?

Have you been able to send a single email (not from a form, just the basic email tutorial in the wiki)?
Joehoch
Forum Newbie
Posts: 5
Joined: Tue Jan 20, 2009 9:08 pm

Re: Complete example snippets

Post by Joehoch »

I'd like to just be able to find the wiki. :lol:

No Chris, I am getting nowhere fast. This whole thing is so far above my level of understanding it's embarrassing.

I started out trying to build something just from the document examples, by adding code to a test script as I worked down the list. That's just making a mess.

As I mentioned in my first post, I am not looking for a lot of capability variety, just looking for a very basic functioning example that I could use to modify into something usable for my purposes.

Frankly I could get away with php's embedded Mail() is it weren't for the need to authenticate to a remote mail system. That one complication is what has sent me looking for something to make quick use out of. As you can tell, php development is not my normal gig.

In mail() this works:

$subject = "Email Verification for submission ".$_POST['reg_user'];
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\n";
$headers .= "From: Music Archives <admin@".$domain.".com>\n";
@mail($_POST['reg_email'], $subject, $message, $headers);

As I mentioned, the bad is (as you know) that mail() does not provide for smtp / authentication. I just need to do the above plus:

$smtp =& new Swift_Connection_SMTP("outbound.services.net");
$smtp->setUsername("use");
$smtp->setPassword("pass");

Yes, I know I can't mix them. Just showing you what I am attempting to accomplish. I figured surely there was some fully functional example somewhere to accomplish this task. However, that basic example eludes me.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Complete example snippets

Post by Chris Corbyn »

Is your question just how to send an email over SMTP, using authentication?

Take this example:

http://swiftmailer.org/wikidocs/v3/tutorials/basic

Then modify the line:

Code: Select all

//Start Swift
$swift =& new Swift(new Swift_Connection_SMTP("smtp.your-host.tld"));
 
According the the page that explains using authentication:

http://swiftmailer.org/wikidocs/v3/smtpauth

Code: Select all

$smtp = new Swift_Connection_SMTP('smtp.your-host.tld');
$smtp->setUsername('username here');
$smtp->setPassword('password here');
 
$swift = new Swift($smtp);
Joehoch
Forum Newbie
Posts: 5
Joined: Tue Jan 20, 2009 9:08 pm

Re: Complete example snippets

Post by Joehoch »

My apologies Chris..

Guess I was trying to overtake the plumbing. It was much easier than I thought at first glance. See I was attempting to take ALL those sections and combine them into a monster. Not good.

Just using those two sections you pointed out, it worked. Sorry to steal your time.

> Joe
Post Reply