log not working

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
tgavin
Forum Newbie
Posts: 15
Joined: Sun Aug 26, 2007 3:13 pm

log not working

Post by tgavin »

I'm trying to print out the failed recipients log (hopefully, I'll be able to add them into mysql later!). I've followed the examples, but for some reason the log isn't working for me. Usually is a non object error that's thrown. 3.3.1 PHP 4

Code: Select all

require_once "includes/mail/swift/Swift.php";
	require_once "includes/mail/swift/Swift/Connection/Sendmail.php";
	$log =& Swift_LogContainer::getLog();
	$log->setLogLevel(SWIFT_LOG_EVERYTHING);

	//Try to connect using /usr/sbin/sendmail -bs
	$swift =& new Swift(new Swift_Connection_Sendmail());
	
	// OR
	//Let the connection try to work out the path itself (PHP4)
	//$swift =& new Swift(new Swift_Connection_Sendmail(SWIFT_SENDMAIL_AUTO_DETECT));

	// build the HTML part of the message
	$html_message = file_get_contents('../data/cache/files/cache_html.php');

	// build the text part of the message
	$text_message = '';
	if($row_prefs['use_nospam_head'] == 1) {
		$text_message .= "\n".$row_prefs['nospam_head']."\n";
	}
	$text_message .= file_get_contents('../data/cache/files/cache_text.php');
	if($row_prefs['use_nospam_foot'] == 1) {
		$text_message .= "\n".$row_prefs['nospam_foot']."\n";
	}
	$text_message .= POWERED_BY_TXT;
	
	
	$message =& new Swift_Message($subject);
	
	//Add the "parts"
	$message->attach(new Swift_Message_Part($text_message));
	$message->attach(new Swift_Message_Part($html_message, "text/html"));
	
	if(VERSION == 1 && $row_prefs['sent_status'] == 1) {
		// if we want confirmation that the recipient read the email
		mysql_select_db($database, $conn) or die(mysql_error());
		$sql = mysql_query("SELECT email_contact FROM {$database}.admin WHERE username = '{$_SESSION['username']}'") or die(sql_error('could not retrieve admin contact email address: functions/email.php'));
		$row_admin = mysql_fetch_array($sql);
		$message->requestReadReceipt($from_address);
	}
	
	// build the recipients list
	$recipients =& new Swift_RecipientList();
	$recipients->addTo($to);
	
	// bounce address
	$message->setReturnPath(new Swift_Address($reply_address));
	
	//And send like usual
	if ($swift->batchSend($message, $recipients, new Swift_Address($reply_address, $row_prefs['eName']))) {
		$sent = true;
	}
	echo "<pre>" . htmlentities($swift->log->dump(true)) . "</pre>";
	$swift->disconnect();
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Ah, sorry I need to update some parts of the documentation after changing this in version 3.3.

Code: Select all

$log =& Swift_LogContainer::getLog();
var_dump($log->getFailedRecipients());
Basically I changed the log so it's no longer nested inside the Swift instance because it was impossible to debug errors when something goes wrong in the constructor of Swift.

EDIT | Hmm, looks I already updated this anyway, and you're using the new code, except you've left a call to $swift->log where it should just be $log ;)
tgavin
Forum Newbie
Posts: 15
Joined: Sun Aug 26, 2007 3:13 pm

Post by tgavin »

Thanks for the quick reply.

It now seems to be working, however I put an email in my list that should have bounced immediately and it didn't.

The email address: fsdjfhsdhfkjhsd@jdhfkjshfkjhsf.com
The var_dump(): array(0) { } array(0) { }

Shouldn't Swiftmailer have sent that back to me as a hard bounce?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

tgavin wrote:Thanks for the quick reply.

It now seems to be working, however I put an email in my list that should have bounced immediately and it didn't.

The email address: fsdjfhsdhfkjhsd@jdhfkjshfkjhsf.com
The var_dump(): array(0) { } array(0) { }

Shouldn't Swiftmailer have sent that back to me as a hard bounce?
Did batchSend() return true? If your mail server accepts the email there's nothing Swift can do. It can't detect "bounces", it can only detect failures at SMTP-time ;)
tgavin
Forum Newbie
Posts: 15
Joined: Sun Aug 26, 2007 3:13 pm

Post by tgavin »

d11wtq wrote:Did batchSend() return true? If your mail server accepts the email there's nothing Swift can do. It can't detect "bounces", it can only detect failures at SMTP-time ;)
Yep. It returned true.
I would think that an email like that would be returned at SMTP-time?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

tgavin wrote:
d11wtq wrote:Did batchSend() return true? If your mail server accepts the email there's nothing Swift can do. It can't detect "bounces", it can only detect failures at SMTP-time ;)
Yep. It returned true.
I would think that an email like that would be returned at SMTP-time?
It depends on the configuration of the server. Your server is not rejecting it, it's just going to wait and see if it bounces later (it'll be spooled first). Most servers have an option to enable host lookups, but it looks like your has this turned off. Nothing to do with Swift either way ;)
tgavin
Forum Newbie
Posts: 15
Joined: Sun Aug 26, 2007 3:13 pm

Post by tgavin »

d11wtq wrote:
tgavin wrote:
d11wtq wrote:Did batchSend() return true? If your mail server accepts the email there's nothing Swift can do. It can't detect "bounces", it can only detect failures at SMTP-time ;)
Yep. It returned true.
I would think that an email like that would be returned at SMTP-time?
It depends on the configuration of the server. Your server is not rejecting it, it's just going to wait and see if it bounces later (it'll be spooled first). Most servers have an option to enable host lookups, but it looks like your has this turned off. Nothing to do with Swift either way ;)
Regardless, thanks for your help and thanks for creating a terrific library. As I was working on this yesterday, I was switching my system over from phpmailer. No regrets :)
Post Reply