Custom from address/name-not working with SMTP thru Exchange

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
batfastad
Forum Contributor
Posts: 433
Joined: Tue Mar 30, 2004 4:24 am
Location: London, UK

Custom from address/name-not working with SMTP thru Exchange

Post by batfastad »

Hi everyone

I already use SwiftMailer in a couple of small scenarios on various sites I've built... mainly as a safer and easier alternative to PHP's mail function, for sending the results of website forms.
However I'm starting to convert our beast newsletter sending system from PHPMailer to Swift

Using PHPMailer we currently send them using SMTP and have PHPMailer sat on our ISPs free webspace using their SMTP server (I checked with the ISP directly when setting that up and they had no problems with that as a set-up).

Now though I want to speed things up a bit and run it from our intranet Apache server, and sending through our local Exchange SBS 2003 server.
Our Exchange server is configured to then relay all outgoing messages to our ISP's server.

After doing some tests, it's all up and running and works for sending single emails through a dedicated account on our Exchange server. I'm assuming that there won't be any problems with sending batches either.

However I can't seem to customise the From: name in Swift.

Here's the code I use to send a single email:

Code: Select all

$swift->send($message, $email, new Swift_Address('newsletter@abcinc.com', 'ABC Newsletter'));
But when the email arrives in GMail, Outlook or an account in Thunderbird, there is no text in the From: field, just the e-mail address!

However when using Swift on my ISP's server and sending through SMTP/nativemail this works without any problems!
And also when using NativeMail on out intranet, it works perfectly, showing ABC Newsletter [newsletter@abcinc.com] in the From: box in Outlook

So it seems Exchange is stripping this out.
Anyone experienced this with Exchange before, and have any ideas on how to solve it?

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

Re: Custom from address/name-not working with SMTP thru Exchange

Post by Chris Corbyn »

Sounds weird. Do you call any methods on $message? Specifically, are you calling $message->setFrom() before hand (you don't need to, but doing so would change the behaviour).
User avatar
batfastad
Forum Contributor
Posts: 433
Joined: Tue Mar 30, 2004 4:24 am
Location: London, UK

Re: Custom from address/name-not working with SMTP thru Exchange

Post by batfastad »

Hi Chris

The only $message call things I've got are:

Code: Select all

$message =& new Swift_Message($subject);
$message->attach(new Swift_Message_Part($body_text));
$message->attach(new Swift_Message_Part($body_html, 'text/html'));
What's the syntax of $message->setFrom()?
I'll give it a go. It says string in the automatic docs, but is it like this...

Code: Select all

$message->SetFrom('ABC Newsletter <newsletter@abc.com>');
Stupid Exchange - it can't do anything right :roll:

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

Re: Custom from address/name-not working with SMTP thru Exchange

Post by Chris Corbyn »

Code: Select all

$message->setFrom(new Swift_Address('newsletter@abc.com', 'ABC Newsletter'));
But don't do that (at least not until version 4 comes out!). Swift does this automatically during sending.

Exchange may be setting a Sender: header instead perhaps? Or maybe it's a security setting so you can't mask the address? Not sure really.
User avatar
batfastad
Forum Contributor
Posts: 433
Joined: Tue Mar 30, 2004 4:24 am
Location: London, UK

Re: Custom from address/name-not working with SMTP thru Exchange

Post by batfastad »

Ah right, I'm still using the latest v3

This gets weirder!
Just tried changing the From: email address to an address outside of the domain scope of the Exchange server (eg: a gmail address), and it not only lets me send properly, but also the From name is changed correctly!

I would have thought Exchange would prevent sending from e-mail addresses that are different to those in the domain - but that's probably our settings.

Then when I try sending from an e-mail address that is a proper Exchange mailbox, Exchange replaces the From: name with whatever that user's display name is according to the mailbox configuration.

Our usual From: e-mail address (newsletter@abc.com) for these newsletters goes to a public folder, which has become a spambox. So as far as Exchange is concerned, it's not an actual mailbox.

After more testing, it appears that it's Outlook 2003 causing the problems.
The From: name appears correctly in Gmail, and any accounts in Thunderbird.

Also when I view the headers in Outlook, I see this...

Code: Select all

Microsoft Mail Internet Headers Version 2.0
Received: from [192.168.1.5] ([192.168.1.5] RDNS failed) by dealer-world.com with Microsoft SMTPSVC(6.0.3790.211);
     Tue, 13 May 2008 13:51:37 +0100
Return-Path: <newsletter@abc.com>
To: testuser@blahblah.com
From: ABC Newsletter <newsletter@abc.com>
Reply-To: ABC Newsletter <newsletter@abc.com>
 
So it appears Exchange is preserving the headers, it's just Outlook messing them up.

So, I guess this is solved. It's a problem with Outlook rather than Swift, and hopefully should be fine for external users

Thanks for your help and I'll see if I can get any more info ;)
Post Reply