Page 1 of 1
Not sending to outside email addresses?
Posted: Tue Mar 20, 2007 5:40 pm
by seodevhead
Hey guys... I am trying to use SwiftMailer to send out a confirmation email when a user signs up for something. The odd thing is, it works perfect if the receipient is an email address residing on my server (ie. my email address), but no emails are being sent if the recipient is anyone else (ie.
anyone@devnet.com, hotmail, gmail, etc). Any idea why it is sending to emails that's accounts are on my server (even across different domains on the server), and not to any other email recipients?
Here is my code:
Code: Select all
# NOTE: IF PHP5 => Take out the & in =&
$swift =& new Swift(new Swift_Connection_SMTP("mail.mydomain.com"));
//Create a message
$message =& new Swift_Message("MyDomain.Com");
$textBody = 'Thank you for registering';
$htmlBody = '<b>Thank you for registering</b>';
//Add some "parts"
$message->attach(new Swift_Message_Part("$textBody"));
$message->attach(new Swift_Message_Part("$htmlBody", "text/html"));
$emailToSendTo = 'anyone@hotmail.com';
//And send like usual
if ($swift->send($message, $emailToSendTo, "help@mydomain.com"))
$confirmEmailSent = TRUE;
else
$confirmEmailSent = FALSE;
$confirmEmailSent is always false if I use
anything@anything.com, but is true if I use
anything@mydomain.com or even anything@{other domains hosted on my server}.com.
Posted: Tue Mar 20, 2007 5:45 pm
by Chris Corbyn
Code: Select all
# NOTE: IF PHP5 => Take out the & in =&
$swift =& new Swift(new Swift_Connection_SMTP("mail.mydomain.com"));
//Enable transaction logging
$swift->log->enable();
$swift->log->setMaxSize(0);
//Create a message
$message =& new Swift_Message("MyDomain.Com");
$textBody = 'Thank you for registering';
$htmlBody = '<b>Thank you for registering</b>';
//Add some "parts"
$message->attach(new Swift_Message_Part("$textBody"));
$message->attach(new Swift_Message_Part("$htmlBody", "text/html"));
$emailToSendTo = 'anyone@hotmail.com';
//And send like usual
if ($swift->send($message, $emailToSendTo, "help@mydomain.com"))
$confirmEmailSent = TRUE;
else
$confirmEmailSent = FALSE;
//Dump the log contents
echo "<pre>" . $swift->log->dump() . "</pre>";
Output please

Posted: Tue Mar 20, 2007 6:27 pm
by seodevhead
I went ahead and added the logging code but for some reason nothing was being output. Though I went ahead and installed the /test folder in my swift installation on the server and ran all the smoke tests. None of them passed, they all failed. Then I took a closer look at the TestConfiguration.php file and noticed that perhaps I needed to allow SMTP authentication (which my server does require). So I added my user/pass for the From: email account within TestConfiguration. Then all my smoke tests PASSED.
So thinking that was my problem, I added the following code to my original code:
Code: Select all
$swift->setUsername("myusername");
$swift->setPassword("mypassword");
Code: Select all
# NOTE: IF PHP5 => Take out the & in =&
$swift =& new Swift(new Swift_Connection_SMTP("mail.mydomain.com"));
//Create a message
$message =& new Swift_Message("MyDomain.Com");
$textBody = 'Thank you for registering';
$htmlBody = '<b>Thank you for registering</b>';
//Add some "parts"
$message->attach(new Swift_Message_Part("$textBody"));
$message->attach(new Swift_Message_Part("$htmlBody", "text/html"));
$emailToSendTo = 'anyone@hotmail.com';
//And send like usual
if ($swift->send($message, $emailToSendTo, "help@mydomain.com"))
$confirmEmailSent = TRUE;
else
$confirmEmailSent = FALSE;
However, after testing it, I get the following error:
Fatal error: Call to undefined function: setusername() in /home/usr/htdocs/folder/file.php on line 488
Any idea what could be causing this? Thanks for any help.

Posted: Tue Mar 20, 2007 6:41 pm
by seodevhead
I think I got it. I changed the initial instantiation to not be a double instantiation (I'm not an OO guy so excuse my lingo..hehe).
Code: Select all
# NOTE: IF PHP5 => Take out the & in =&
$smtp =new Swift_Connection_SMTP("mail.mydomain.com");
$smtp = setUsername("XXX");
$smtp = setPassword("XXX");
$swift =& new Swift($smtp);
So, now it works!
Problem is all my emails are still getting dumped to the spam folders... but that doesn't have anything to do with my swiftmailer setup, right? That just has to do with my wording and server setup (rDNS, etc)?
Posted: Wed Mar 21, 2007 2:34 am
by Chris Corbyn
It's most likely due to the configuration of the server.
http://www.swiftmailer.org/wikidocs/v3/tips_spam
Check blacklists
Check SPF records
Send from a real address