use*_*496 1 php email smtp localhost
我正在使用这个非常小的代码来测试电子邮件是否到达电子邮件目的地:
<?php
mail('woodsy013@hotmail.com','Test mail','The mail function is working!');
echo 'Mail sent!';
?>
Run Code Online (Sandbox Code Playgroud)
但它似乎没有工作。我正在使用 WAMP。我已经安装了一个免费的 SMTP 服务器。我的 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
Run Code Online (Sandbox Code Playgroud)
按照我提到的操作,我似乎没有收到发送至 woodsy130@hotmail.com 的电子邮件。
我收到此错误:
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
Run Code Online (Sandbox Code Playgroud)
有什么建议?
尝试在 gmail 中使用 SMTP 服务器。
ini_set("SMTP","ssl://smtp.gmail.com");
ini_set("smtp_port","465");
Run Code Online (Sandbox Code Playgroud)
或者有很多PHP邮件程序库。这为您简化了事情并使其更易于使用。我最喜欢的是 swift mailer。最好的部分是你不必弄乱你的核心 php 配置文件,而且文档也很容易阅读。
例如,如果您想使用 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);
Run Code Online (Sandbox Code Playgroud)
你可以参考官方网站http://swiftmailer.org/docs上的文档了解更多信息
| 归档时间: |
|
| 查看次数: |
5508 次 |
| 最近记录: |