[SMTP] sending emails...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
EmuBro
Forum Newbie
Posts: 3
Joined: Sun Oct 08, 2006 11:49 pm

[SMTP] sending emails...

Post by EmuBro »

Hey guys,

I've made a script that uses a FOREACH to create each individual email and send it, and start over.

When i made it with mail() it worked perfectly, so i decided to make it more efficient and make it use SMTP,
Ive had a few problems with the emails then i worked them out.

Now im having another one,

Right after the script sends the mail to the users in the array, It instantly (at the end of the FOREACH cycle) sends an email directly to me letting me know of the statistics etc.

Right now, The last person of the foreach cycle is being sent that email instead of me, even though the headers are all changed. Infact the email that arrives has the headers that dictate it should have been sent to my "admin" email, not that person.

I theorized that id probably have to close the SMTP connection after the end of the FOREACH and start another one after.

BUT, Problem. I don't know how to use classes very well, and i tried using

$smtp->quit(); but it doesnt work.

any hints to how i might get it to stop?

Here's the CLASS section that tells it to DIE.

Code: Select all

/***************************************
        ** Function to implement QUIT cmd
        ***************************************/

		function quit(){
			$this->errors[] = '';
			if(is_resource($this->connection)
					AND $this->send_data('QUIT')
					AND substr(trim($error = $this->get_data()), 0, 3) === '221' ){

				fclose($this->connection);
				$this->status = SMTP_STATUS_NOT_CONNECTED;
				return TRUE;

			}else{
				$this->errors[] = 'QUIT command failed, output: ' . trim(substr(trim($error),3));
				return FALSE;
			}
		}
How do I call that in my script correctly to shut down the connection to the SMTP?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

What's not working? Does it hang or give you an error? If you call it too late in PHP4 (i.e. at shutdown time) then it will hang since the resource needs to be global or PHP loses contact with it.

Maybe you'll want to have a look at Swift Mailer and either use it instead, or steal what you need from it.
Post Reply