Chris Corbyn wrote:Does your ISP not provide an SMTP server?
They do, but it has a bad reputation with senderscore.org.
Anyway, I tried to use your code:
Code: Select all
if ($swift->connection === $gmailConnection) {
//is gmail
}
and
Code: Select all
if ($swift->connection->getServer() == 'smtp.gmail.com') {
//is gmail
}
But neither seem to work. Here's my code:
Code: Select all
// Initialize SwiftMailer
$connections_gmail = array();
$connections_def = array();
$conn_g =& new Swift_Connection_SMTP("smtp.gmail.com", SWIFT_SMTP_PORT_SECURE, SWIFT_SMTP_ENC_TLS);
$conn_g->setUsername("email1@gmail.com");
$conn_g->setPassword("mypass");
$connections_gmail[] =& $conn_g;
$conn_g2 =& new Swift_Connection_SMTP("smtp.gmail.com", SWIFT_SMTP_PORT_SECURE, SWIFT_SMTP_ENC_TLS);
$conn_g2->setUsername("email2@gmail.com");
$conn_g2->setPassword("mypass");
$connections_gmail[] =& $conn_g2;
// Add another Gmail connection here if needed. Will also have to edit function gmail_conn() if you do so.
$conn_s =& new Swift_Connection_Sendmail();
$connections_gmail[] =& $conn_s;
$connections_def[] =& $conn_s;
$conn_n =& new Swift_Connection_NativeMail();
$connections_gmail[] =& $conn_n;
$connections_def[] =& $conn_n;
$mailer_gmail =& new Swift(new Swift_Connection_Multi($connections_gmail));
$mailer_def =& new Swift(new Swift_Connection_Multi($connections_def));
//1 mails per batch with a 10 second pause between batches (Author suggests 100/batch, 30 sec.
$mailer_gmail->attachPlugin(new Swift_Plugin_AntiFlood(1, 10), "anti-flood");
$mailer_def->attachPlugin(new Swift_Plugin_AntiFlood(1, 10), "anti-flood");
function gmail_conn() {
global $mailer_gmail, $conn_s, $conn_n, $conn_g, $conn_g2; // When adding a new Gmail connection, don't forget to add it here too.
if ($mailer_gmail->connection === $conn_g) {
return "Gmail #1 (".$mailer_gmail->connection->getUsername().") ({$mailer_gmail->connection})";
} else if($mailer_gmail->connection === $conn_g2) {
return "Gmail #2 ($mailer_gmail->connection)";
// Add new Gmail connections here
} else {
if($mailer_gmail->connection === $conn_s) return "Sendmail";
if($mailer_gmail->connection === $conn_n) return "Native";
echo $mailer_gmail->connection->getServer();
echo $mailer_gmail->connection->getUsername();
}
}
This code reports that $mailer_gmail->connection is none of the connections (though using $mailer_gmail to send stuff works and does use Gmail's SMTP server). $mailer_gmail->connection->getServer() and $mailer_gmail->connection->getUsername() do not work because $mailer_gmail->connection doesn't have the getServer() or getUsername() properties.
AH! While writing this, I tried different code, and it worked! I think because the connection is a Multi, you have to do:
$mailer_gmail->connection->connections[$mailer_gmail->connection->active] instead of just $mailer_gmail->connection.
Thus, to get the Server and Username, it should be:
$mailer_gmail->connection->connections[$mailer_gmail->connection->active]->getServer()
$mailer_gmail->connection->connections[$mailer_gmail->connection->active]->getUsername()
Or you could just use $mailer_gmail->connection->active, and if it's zero, it means the active connection is the first one, etc.