我可以在不定义用户名和密码的情况下将 SMTP 与 Swift Mailer 一起使用吗

发布于 2024-10-31 06:20:54 字数 164 浏览 1 评论 0 原文

我正在尝试使用 Swift Mailer 在她的网站上向客户发送电子邮件。问题是,我不知道她的用户名/密码电子邮件信息,而且我不想使用我的。

有没有办法将 SMTP 与 Swift Mailer 一起使用,而不定义用户名、密码或电子邮件主机?邮件功能将如何允许您使用任何内容作为收件人/发件人地址。

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 not define a username, password, or email host? Kinda how the mail function will allow you to use anything for the to/from addresses.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

芸娘子的小脾气 2024-11-07 06:20:54

这就是我为我们的一个脚本所做的,我相信它正是这样做的。

    $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);

这可能是从 Swift 邮件程序文档中复制粘贴并稍加修改的。我们所做的就是连接到本地主机上的 SMTP。

编辑:查看原始帖子的评论,我确实想知道是否会触发垃圾邮件过滤器。我们实际上并没有遇到任何问题...一个,也许两个用户抱怨没有收到电子邮件。如果有关于此类内容的任何好的文档以及避免这些问题的方法,我很乐意提供其链接。我想我们只是在我们的机器上运行了由我们的提供商设置的默认 IIS SMTP 服务器。

另一个编辑:啊,如果这是在其他人的网站上发生的,我们不知道他们到底是如何设置的。我想知道您是否可以在其他电子邮件提供商处创建一个帐户(假设这不违反他们的使用条款)。也许我的帖子太仓促了,抱歉。

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.

又爬满兰若 2024-11-07 06:20:54

为了正确执行此操作,您必须使用真实的电子邮件地址并从正确配置的服务器发送。否则您的邮件最终进入他们的垃圾邮件箱。

只需让您的客户设置一个名为 这会是为了这个。如果由于某种愚蠢的原因他们不能这样做,那么在 gmail 或其他一些免费电子邮件提供商处设置一个邮件地址,并通过他们的邮件服务器发送。

在当今世界,正确配置邮件服务器需要做很多工作。从黑名单管理、反向 DNS 配置、SPF 设置等。重点是提供商每天都变得越来越挑剔,如果您希望看到您的应用程序长期运行,那么您需要正确执行此操作。

希望有帮助。

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 [email protected] 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文