简体   繁体   English

从 windows 中的 php 中的本地主机发送 email

[英]Sending email from localhost in php in windows

I am using this very tiny piece code to test whether an email reaches the email destination:我正在使用这个非常小的代码来测试 email 是否到达 email 目的地:

<?php
  mail('woodsy013@hotmail.com','Test mail','The mail function is working!');
  echo 'Mail sent!';
?>

But it doesnt seem to be working.但它似乎没有用。 I am using WAMP.我正在使用 WAMP。 I have installed a free SMTP server.我已经安装了一个免费的 SMTP 服务器。 And my php.ini file is configured to the following:我的 php.ini 文件配置如下:

[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = smtp.tools.sky.com
; http://php.net/smtp-port
smtp_port = 25

; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = you@yourdomain

I dont seem to be receiving an email to woodsy130@hotmail.com following the actions I have mentioned.按照我提到的操作,我似乎没有收到 woodsy130@hotmail.com 的 email。

I get this error:我收到此错误:

Warning: mail() [function.mail]: SMTP server response: 530 5.7.0 
Must issue a STARTTLS command first. ff2sm10904265wib.9 in 
C:\wamp\www\Derrysgc2\pages\pages\mailtest.php on line 2

Any suggestions?有什么建议么?

Try using SMTP server with gmail.尝试将 SMTP 服务器与 gmail 一起使用。

ini_set("SMTP","ssl://smtp.gmail.com");
ini_set("smtp_port","465");

or else there are many PHP mailer library.否则有很多 PHP 邮件程序库。 which simplifies things for you and makes it so easier to use.这为您简化了事情并使其更易于使用。 my fav is swift mailer.我最喜欢的是 swift 邮件。 the best part about is you don't have to mess with your core php configuration file and the documentation too is very easy to read.最好的部分是您不必弄乱核心 php 配置文件,而且文档也非常易于阅读。

for example if you want to send a mail using PHP's swift mailer library it is as simple as.例如,如果您想使用 PHP 的 swift 邮件程序库发送邮件,它就很简单。

require_once 'lib/swift_required.php';

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

// Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);

// Create a message
$message = Swift_Message::newInstance('Wonderful Subject')
  ->setFrom(array('john@doe.com' => 'John Doe'))
  ->setTo(array('receiver@domain.org', 'other@domain.org' => 'A name'))
  ->setBody('Here is the message itself');

// Send the message
$result = $mailer->send($message);

you can refer the documentation for more information on the official website http://swiftmailer.org/docs您可以在官方网站http://swiftmailer.org/docs上参考文档以获取更多信息

Shouldn't SMTP point to your SMTP server? SMTP 不应该指向您的 SMTP 服务器吗? (I am assuming smtp.tools.sky.com is your provider). (我假设 smtp.tools.sky.com 是您的提供商)。 Also sendmail_from should be a correct emailaddress. sendmail_from 也应该是正确的电子邮件地址。

Also note some mail provders block email sent from dynamic ip adresses.还要注意一些邮件提供者阻止从动态 ip 地址发送的 email。

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

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