使用Mac Yosemite使用XAMPP和PHP发送电子邮件

时间:2022-10-23 17:07:32

I am really confused on where to start with sending emails. I have search the web but the amount of content available for different packages and softwares has really confused me. I was wondering if anyone here had a simple or knows of a simple tutorial of how i can send an email using xampp.

我真的很困惑从哪里开始发送电子邮件。我在网上搜索,但可用于不同软件包和软件的内容量让我很困惑。我想知道这里是否有人有一个简单或知道如何使用xampp发送电子邮件的简单教程。

Im new to using local host and so far have only used MySQL and Apache from xampp to load and view my php files for an application.

我是新手使用本地主机,到目前为止只使用xampp中的MySQL和Apache来加载和查看我的应用程序的php文件。

I would really appreciate it if anyone could help me start setting up XAMPP to send emails when i use the php.

我真的很感激,如果有人能帮助我开始设置XAMPP来发送电子邮件,当我使用PHP。

Some sites suggest a separate server is needed for emails such as PHPMailer while others suggest a few config changes need making like changing in the php.ini files which I'm very cautious to change incase my whole xampp crashes!

有些网站建议像PHPMailer这样的电子邮件需要单独的服务器,而其他网站则建议进行一些配置更改需要更改php.ini文件,我非常谨慎地改变我的整个xampp崩溃!

is this link any good? http://www.websnippetz.com/2013/01/send-email-from-xampp-localhost.html Many are using SendMail package with XAMPP but i can't find a download for that.

这个链接有什么好处吗? http://www.websnippetz.com/2013/01/send-email-from-xampp-localhost.html许多人正在使用带有XAMPP的SendMail软件包,但我无法找到它的下载。

anyone tried anything which worked for them?

有人试过任何适合他们的东西吗?

please help a very confused developer guys!

请帮助一个非常困惑的开发人员!

2 个解决方案

#1


0  

To send emails from your localhost your need an Email-Server like postfix or Exim or you send your E-Mails over SMTP what is described on that site from your link.

要从本地主机发送电子邮件,您需要一个像postfix或Exim这样的电子邮件服务器,或者通过SMTP从您的链接发送该网站上描述的电子邮件。

The easiest way is to use an abstraction layer like Swift Mailer

最简单的方法是使用像Swift Mailer这样的抽象层

http://swiftmailer.org/docs/sending.html

Here you have a lot of possibilities to send E-Mails. Another solution is to install a local Mailserver and fetch all sending E-Mails. In MAMP Pro for example you have an integrated Mailserver.

在这里,你有很多可能发送电子邮件。另一种解决方案是安装本地邮件服务器并获取所有发送电子邮件。例如,在MAMP Pro中,您有一个集成的邮件服务器。

http://blog-en.mamp.info/2009/09/how-to-sending-emails-with-mamp-pro.html

#2


0  

Some sites suggest a separate server is needed for emails such as PHPMailer while others suggest a few config changes need making like changing in the php.ini files which I'm very cautious to change incase my whole xampp crashes!

有些网站建议像PHPMailer这样的电子邮件需要单独的服务器,而其他网站则建议进行一些配置更改需要更改php.ini文件,我非常谨慎地改变我的整个xampp崩溃!

PHPMailer is not a server it is a library. People often recommend using a Mail library because the built mail functions are very low level and hard to work with. Because they are modeled after using sendmail from the commandline.

PHPMailer不是服务器它是一个库。人们经常建议使用邮件库,因为构建的邮件功能非常低级且难以使用。因为它们是在命令行使用sendmail后建模的。

If you want to send via SMTP, use attachments, or other things it can be difficult or impossible to do with mail() directly.

如果您想通过SMTP发送,使用附件或其他东西,可能很难或不可能直接使用mail()。

Personally I recommend using SwiftMail over PHP mailer. IMO, it's more modern, easier to use, and has a better API, and depending on which PHP F/OSS projects you are used to using or contributing to its more common and the standard.

我个人建议使用SwiftMail而不是PHP邮件程序。 IMO,它更现代,更易于使用,并且具有更好的API,并且取决于您习惯使用或贡献其更常见和标准的PHP F / OSS项目。

Overall there are 2 parts to sending mail from PHP:

总的来说,从PHP发送邮件有两个部分:

  1. Setup of the actual mail server on a system (local or otherwise)
  2. 在系统上设置实际的邮件服务器(本地或其他)

  3. The configuration of PHP to use that mail server.
  4. PHP的配置使用该邮件服务器。

To setup the mail function you need to install and configure a mail server locally in order to fulfill item (1). This should already be included and set up on OSX. So to fulfill item (2) you need to configure PHP via the INI to use that mail server by changing the sendmail_path.

要设置邮件功能,您需要在本地安装和配置邮件服务器以实现第(1)项。这应该已经包含在OSX中并进行设置。因此,为了实现第(2)项,您需要通过INI配置PHP以通过更改sendmail_path来使用该邮件服务器。

Now if you want to use a library, which I recommend you need to get that source into your project and then use it appropriately. For the example we will use SwiftMailer, with SMTP transport via a gmail account:

现在,如果您想使用库,我建议您需要将该源添加到项目中,然后适当地使用它。对于该示例,我们将使用SwiftMailer,通过gmail帐户进行SMTP传输:

require_once 'PATH/TO/swift_required.php';

// Create the Transport
$transport = Swift_SmtpTransport::newInstance('smtp.googlemail.com', 465, 'ssl')
  ->setUsername('user@gmail.com')
  ->setPassword('secret');

$mailer = Swift_Mailer::newInstance($transport);

$message = Swift_Message::newInstance('My SMTP Message')
  ->setFrom(array('john@doe.com' => 'John Doe'))
  ->setTo(array('receipient@domain.com', 'other@domain.com' => 'A name'))
  ->setBody('Plain Text Message Body');

$mailer->send($message);

#1


0  

To send emails from your localhost your need an Email-Server like postfix or Exim or you send your E-Mails over SMTP what is described on that site from your link.

要从本地主机发送电子邮件,您需要一个像postfix或Exim这样的电子邮件服务器,或者通过SMTP从您的链接发送该网站上描述的电子邮件。

The easiest way is to use an abstraction layer like Swift Mailer

最简单的方法是使用像Swift Mailer这样的抽象层

http://swiftmailer.org/docs/sending.html

Here you have a lot of possibilities to send E-Mails. Another solution is to install a local Mailserver and fetch all sending E-Mails. In MAMP Pro for example you have an integrated Mailserver.

在这里,你有很多可能发送电子邮件。另一种解决方案是安装本地邮件服务器并获取所有发送电子邮件。例如,在MAMP Pro中,您有一个集成的邮件服务器。

http://blog-en.mamp.info/2009/09/how-to-sending-emails-with-mamp-pro.html

#2


0  

Some sites suggest a separate server is needed for emails such as PHPMailer while others suggest a few config changes need making like changing in the php.ini files which I'm very cautious to change incase my whole xampp crashes!

有些网站建议像PHPMailer这样的电子邮件需要单独的服务器,而其他网站则建议进行一些配置更改需要更改php.ini文件,我非常谨慎地改变我的整个xampp崩溃!

PHPMailer is not a server it is a library. People often recommend using a Mail library because the built mail functions are very low level and hard to work with. Because they are modeled after using sendmail from the commandline.

PHPMailer不是服务器它是一个库。人们经常建议使用邮件库,因为构建的邮件功能非常低级且难以使用。因为它们是在命令行使用sendmail后建模的。

If you want to send via SMTP, use attachments, or other things it can be difficult or impossible to do with mail() directly.

如果您想通过SMTP发送,使用附件或其他东西,可能很难或不可能直接使用mail()。

Personally I recommend using SwiftMail over PHP mailer. IMO, it's more modern, easier to use, and has a better API, and depending on which PHP F/OSS projects you are used to using or contributing to its more common and the standard.

我个人建议使用SwiftMail而不是PHP邮件程序。 IMO,它更现代,更易于使用,并且具有更好的API,并且取决于您习惯使用或贡献其更常见和标准的PHP F / OSS项目。

Overall there are 2 parts to sending mail from PHP:

总的来说,从PHP发送邮件有两个部分:

  1. Setup of the actual mail server on a system (local or otherwise)
  2. 在系统上设置实际的邮件服务器(本地或其他)

  3. The configuration of PHP to use that mail server.
  4. PHP的配置使用该邮件服务器。

To setup the mail function you need to install and configure a mail server locally in order to fulfill item (1). This should already be included and set up on OSX. So to fulfill item (2) you need to configure PHP via the INI to use that mail server by changing the sendmail_path.

要设置邮件功能,您需要在本地安装和配置邮件服务器以实现第(1)项。这应该已经包含在OSX中并进行设置。因此,为了实现第(2)项,您需要通过INI配置PHP以通过更改sendmail_path来使用该邮件服务器。

Now if you want to use a library, which I recommend you need to get that source into your project and then use it appropriately. For the example we will use SwiftMailer, with SMTP transport via a gmail account:

现在,如果您想使用库,我建议您需要将该源添加到项目中,然后适当地使用它。对于该示例,我们将使用SwiftMailer,通过gmail帐户进行SMTP传输:

require_once 'PATH/TO/swift_required.php';

// Create the Transport
$transport = Swift_SmtpTransport::newInstance('smtp.googlemail.com', 465, 'ssl')
  ->setUsername('user@gmail.com')
  ->setPassword('secret');

$mailer = Swift_Mailer::newInstance($transport);

$message = Swift_Message::newInstance('My SMTP Message')
  ->setFrom(array('john@doe.com' => 'John Doe'))
  ->setTo(array('receipient@domain.com', 'other@domain.com' => 'A name'))
  ->setBody('Plain Text Message Body');

$mailer->send($message);