Not sending to outside email addresses?

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
User avatar
seodevhead
Forum Regular
Posts: 705
Joined: Sat Oct 08, 2005 8:18 pm
Location: Windermere, FL

Not sending to outside email addresses?

Post 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.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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 :)
User avatar
seodevhead
Forum Regular
Posts: 705
Joined: Sat Oct 08, 2005 8:18 pm
Location: Windermere, FL

Post 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. :)
User avatar
seodevhead
Forum Regular
Posts: 705
Joined: Sat Oct 08, 2005 8:18 pm
Location: Windermere, FL

Post 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)?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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
Post Reply