mailer not working in another server.

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
kailash badu
Forum Newbie
Posts: 3
Joined: Mon Nov 13, 2006 10:08 pm

mailer not working in another server.

Post by kailash badu »

I am experiencing this weird problem in swiftmailer. It works fine in one of the server, but on the another it fails. the error says:

Code: Select all

The mailer failed to connect. Errors: 


Log:
I also checked phpinfo() . and SMTP is set to localhost. please help me find out the solution. here is the code i have used.

Code: Select all

<?php
require('Swift/Swift.php');
require('Swift/Swift/Connection/SMTP.php');
require("Swift/Swift/Plugin/AntiFlood.php");

$connectionObject = new Swift_Connection_SMTP('localhost');

$swift = new Swift($connectionObject);

if(!$swift->isConnected()) {
	echo "The mailer failed to connect. Errors: <pre>".print_r($mailer->errors, 1)."</pre><br />
	Log: <pre>".print_r($mailer->transactions, 1)."</pre>";
	exit();
}
//100 mails per batch with a 30 second pause between batches
$swift->loadPlugin(new Swift_Plugin_AntiFlood(100, 30));

$recipients = array('kailashbadu@hotmail.com','kailashbadu@gmail.com');
print "<pre>";
print_r($recipients);
print "</pre>";
	 
//Make the script run until it's finished in the background

set_time_limit(0);
ignore_user_abort();

echo "Close the browser window now...";

flush(); 
ob_flush();


$swift->send($recipients, 'bill@sun.com', 'Welcome to sun' , 'we welcome you');
print ("The emails were sent successfully <br>");
print("<pre>");
print_r($mailer->transactions);
print("</pre>");

$swift->close();
?>
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Do both servers actually have an SMTP running on localhost? The phpinfo() details cannot tell you that. You'll want to try using telnet to connect to the server on port 25
kailash badu
Forum Newbie
Posts: 3
Joined: Mon Nov 13, 2006 10:08 pm

Post by kailash badu »

Ok it was because of incorrect SMTP address.

Now when I try sending emails to a few recipients it goes fine. But when doing the same for 1000 of recipients, the page shows internal server error. What could be the likely reason, and how can I fix it. Could it be that my web server isn't taking the load? How do I get around this? I am using the same method as this one.
http://www.swiftmailer.org/docs/faq/mass-mailing

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

Post by Chris Corbyn »

kailash badu wrote:Ok it was because of incorrect SMTP address.

Now when I try sending emails to a few recipients it goes fine. But when doing the same for 1000 of recipients, the page shows internal server error. What could be the likely reason, and how can I fix it. Could it be that my web server isn't taking the load? How do I get around this? I am using the same method as this one.
http://www.swiftmailer.org/docs/faq/mass-mailing

Thanks.
I'd need to see more code (that code is purely sketchey pseudo code). It's unlikely to be a problem with Swift and more likely to do with some memory limit or something more at a server level.
kailash badu
Forum Newbie
Posts: 3
Joined: Mon Nov 13, 2006 10:08 pm

Post by kailash badu »

Code: Select all

<?php
if(isset($_POST['task'])) { 
//Load in the components
require('Swift/Swift.php');
require('Swift/Swift/Connection/SMTP.php');
require("Swift/Swift/Plugin/AntiFlood.php");
require("library/dbConfig.php");
require("library/mysql.class.php");

$message = stripslashes($_POST['message']);
$from = stripslashes($_POST['from']);
$subject = stripslashes($_POST['subject']);

$connectionObject = new Swift_Connection_SMTP('smtp.1and1.com');

$swift = new Swift($connectionObject);

if(!$swift->isConnected()) {
	echo "The mailer failed to connect. Errors: <pre>".print_r($mailer->errors, 1)."</pre><br />
	Log: <pre>".print_r($mailer->transactions, 1)."</pre>";
	exit();
}
//100 mails per batch with a 30 second pause between batches
$swift->loadPlugin(new Swift_Plugin_AntiFlood(10, 30));
$swift->addPart($message, 'text/html');

//create mysql connection
$cnx = new MySQL($database);
$sql =  "select mailing_list.Email as email , mailing_list.Name as name from mailing_list";

$result = $cnx->query($sql);

$recipients = array();
//$recipients = array('kailashbadu@hotmail.com','kailashbadu@gmail.com');
while($row = $result->fetchResult('assoc') ) {
	$recipients[ ] = trim($row['email']);
	//$recipientsDetail[ ] = $row['email'] . " " .$row['name'];
}	

print_r($recipients);

print "From: " . $from . "<br />";
print  "Subject: " .$subject . "<br />";
print  "Message: " . $message . "<br />";

		


//Make the script run until it's finished in the background

set_time_limit(0);
ignore_user_abort();

echo "Close the browser window now...";

flush(); 
ob_flush();


$swift->send($recipients, $from, $subject );
print ("The emails were sent successfully <br>");
print("<pre>");
print_r($mailer->transactions);
print("</pre>");

$swift->close();
}
else {
print "The message form has not been failed";
}
?>
The glitch is certainly not in swift. I believe that may be i am doing something in wrong way. Memory limit is sufficiently high. Here are few settings:

max_execution_time: 30 // doesn’t matter because I have explicitly used set_time_limit();

memory_limit: 8M
max_input_time: -1

If it’s because of Web Server, what is the most likely reason?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

I can't see anything wrong there. I'm not sure what's in the MySQL stuff BUT wither way PHP alone should never give a 500 error. That's more of an issue with a CGI script not working correctly. I'd probably ask 1and1.

FYI: If you're not on a premium account with 1and1 I strongly discourage you to try sending 1000 emails via their smtp.... they'll either block them or disable your account. I belive 1and1 have quite low limits for shared hosting ;)
Post Reply