I am trying to use Swift Mailer to send an email to a client on her website. The problem is, I do not know her username/password email information, and I do not want to use mine.
Is there a way to use SMTP with Swift Mailer, and no开发者_如何学Got define a username, password, or email host? Kinda how the mail function will allow you to use anything for the to/from addresses.
This is what I have for one of our scripts and I believe it does exactly that.
$message = Swift_Message::newInstance()
//Give the message a subject
->setSubject('Webinar Registration')
//Set the From address with an associative array
->setFrom(array('FROM EMAIL ADDRESS' => 'FROM NAME'))
//Set the To addresses with an associative array
->setTo(array('TO EMAIL ADDRESS'))
//Give it a body
->setBody('My Message')
//And optionally an alternative body
//->addPart('<q>Here is the message itself</q>', 'text/html')
;
//Create the Transport
$transport = Swift_SmtpTransport::newInstance('127.0.0.1', 25);
//Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);
//Send the message
$result = $mailer->send($message);
This was probably copy-pasted and slightly modified from the Swift mailer documentation. All we're doing is connecting to SMTP on localhost.
Edit: Looking at comments on the original post, I do have to wonder about triggering spam filters. We haven't really had a problem with it... one, maybe two users have complained about not receiving e-mails. If there's any good documentation on this kind of stuff and ways to avoid these problems, I'd love to have a link to it. I think we just have the default IIS SMTP server running on our machine as set up by our provider.
Another Edit: Ah, if this is going on to someone else's website, we don't know exactly how they're set up. I wonder if you could create an account with some other e-mail provider (assuming it's not against their terms of use.) Maybe I jumped the gun with my post, sorry.
In order to do this right you have to use a real email address and send it from a server that is properly configured. Otherwise your mail will end up in their spam box.
Just have your client set up an email address called support@whateverthedomainis.com which would be for this. If for whatever silly reason they can't do that then set up a mail address at gmail or some other free email provider and send it through their mail server.
There is a LOT that goes into properly configuring a mail server in todays world. From blacklist management, reverse dns configuration, SPF setup, etc. Point is providers are getting more finicky every day and if you want to see your application work long term then you'll need to do this right.
Hope that helps.
精彩评论