简体   繁体   English

如何在Windows计算机上使用swiftmailer发送电子邮件?

[英]How to send an email using swiftmailer on a windows machine?

The swiftmailer documentation explains that for sending an email we have to create a Transport, mailer, message and then send it. swiftmailer文档说明,要发送电子邮件,我们必须先创建传输,邮件,消息,然后再发送。 Now i want to send an email from localhost and how to configure the transport for the windows machine. 现在,我想从本地主机发送电子邮件,以及如何为Windows计算机配置传输。 The dummy code by their documentation is: 他们的文档中的伪代码为:

$transport = Swift_SmtpTransport::newInstance('smtp.example.org', 25)->setUsername('your username')->setPassword('your password');

Now what should be the values of arguments so that being on windows i could send the mail from localhost. 现在参数的值应该是什么,以便在Windows上我可以从本地主机发送邮件。 I 'm using Xampp.Please help me. 我正在使用Xampp。请帮助我。

If by "sending from localhost" you only mean the script runs on localhost, but you are able to send the email from an external server, then you need an SMTP server you can use (for example the one you use for all your email anyway, whichever server that is) and use your credentials as long credentials in the transport. 如果通过“从本地主机发送”仅表示脚本在本地主机上运行,​​但是您能够从外部服务器发送电子邮件,则您需要可以使用的SMTP服务器(例如,无论如何都用于所有电子邮件的服务器) ,无论是哪个服务器),并将您的凭据用作传输中的长凭据。 Nobody can tell you what that is, as we neither now your mail service, nor, obviously, your username and password there. 没有人能告诉您那是什么,因为我们现在既不是您的邮件服务,也不是您那里的用户名和密码。

However if you do not have an external SMTP server to use, or do not want to use one, you need to run an SMTP server on your local machine. 但是,如果您没有要使用的外部SMTP服务器,或者不想使用一台外部SMTP服务器,则需要在本地计算机上运行SMTP服务器。 Covering how to set up an SMTP server on a windows machine is way outside the scope of SO. 涵盖如何在Windows计算机上设置SMTP服务器的方法超出了SO的范围。 However I would not advise to do this outside of testing scenarios anyway, as mail originating from dynamic IP addresses (which you likely ahve) with no valid reverse DNS or reverse DNS that does not match the hostname (which you likely also have) is not accepted by any sane mails server anyway and considered spam. 但是,无论如何我都不建议在测试方案之外进行此操作,因为来自动态IP地址(您可能会收到)的邮件没有有效的反向DNS或与主机名不匹配(您也可能拥有)的反向DNS都不是无论如何,任何理智的邮件服务器都接受该垃圾邮件,并将其视为垃圾邮件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM