我正在尝试通过 Web 表单发送电子邮件,但出现错误......我在 Windows Server 2008 R2(64 位)拆分服务器(2 服务器环境)上配置了我的 php 环境,其中一台服务器运行 mysql另一台服务器运行 php 和 apache(使用 xammp 安装)。运行网站时出现以下错误:
警告:mail() [function.mail]:无法在“localhost”端口 25 连接到邮件服务器,请验证 php.ini 中的“SMTP”和“smtp_port”设置或在 C:\xampp\htdocs\ 中使用 ini_set()在线联系.php
以下是php脚本:
if(empty($_POST) === false)
{
//Array to store and output errors
$errors = array();
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$feedback = $_POST['feedback'];
//check if the all the required fields have been completed
if(empty($name)=== true || empty($email)=== true || empty($subject)=== true || empty($feedback) === true)
{
$errors[] = 'Name, email, subject and message are required';
}
else
{
//check if the email is valid
if(filter_var($email,FILTER_VALIDATE_EMAIL) === false )
{
$errors[] = 'That\'s not a valid email address';
}
//check if the name contains any numbers
if (ctype_alpha($name)=== false)
{
$errors[] = 'Name must only contain letters';
}
}
}
//if there are no errors then send the email
if(empty($errors) === true)
{
//send email
mail('erecruitment@saqa.co.za','$subject','$feedback','FROM:'.'$email');
//redirect users
header('Location: contact.php?sent');
//exit();
}
以下来自 php.ini 文件:
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = localhost
; http://php.net/smtp-port
smtp_port = 25
; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from = me@example.com
我仍在掌握 php,如果有人可以帮助我看看我做错了什么,那就太好了