电子邮件表单.php脚本错误


Email form .php script error

我有一个脚本,里面有一个电子邮件表单,然后我有一份.php脚本,它应该将表单中的输入发送到另一封电子邮件。问题是,当我提交表格时,我会看到下面的错误:

警告:mail():无法连接到"127.0.0.1"端口25的邮件服务器,请验证php.ini中的"SMTP"answers"SMTP_port"设置,或在第16行的C:''Program Files(x86)''EasyHP-DevServer-14.1VC11''data''localweb''scripts''supFormSend.php中使用ini_set()


Html脚本:

<form action="supFormSend.php" method="post" id="contactForms">
    <div id="nameLabelForm">
        <label for="name">Name:</label><br>
        <input type="text" id="nameInput" name="nameInput"/>
    </div>
    <div id="emailLabelForm">
        <label for="mail">E-mail:</label><br>
        <input type="email" id="mailInput" name="mailInput"/>
    </div>
    <div id="messageLabelForm">
        <label for="msg">Support Message:</label><br>
        <textarea id="messageInput" name="messageInput"></textarea>
    </div>
    <div class="submitEmailButton">
        <button type="submit" id="submitButton">Send message</button>
    </div>
</form>

php脚本:

<?php
$field_name = $_POST['nameInput'];
$field_email = $_POST['mailInput'];
$field_message = $_POST['messageInput'];
$mail_to = 'removed for safety';
$subject = 'Message from a site visitor '.$field_name;
$body_message = 'From: '.$field_name."'n";
$body_message .= 'E-mail: '.$field_email."'n";
$body_message .= 'Message: '.$field_message;
$headers = 'From: '.$field_email."'r'n";
$headers .= 'Reply-To: '.$field_email."'r'n";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
if ($mail_status) { ?>
    <script language="javascript" type="text/javascript">
        alert('Thank you for the message. We will contact you shortly.');
        window.location = 'contact.html';
    </script>
<?php
}
else { ?>
    <script language="javascript" type="text/javascript">
        alert('Message failed. Please, send an email to');
        window.location = 'contact.html';
    </script>
<?php
}
?>

错误是抱怨您试图通过不存在的本地SMTP服务器发送电子邮件。如果您正在运行自己的SMTP服务器,则修复服务器;如果您没有,则需要使用ini_set()将PHP指向SMTP服务器,或者在调用mail()之前,如错误消息所示编辑PHP.ini。

例如:

ini_set("SMTP", "mail.example.com");
ini_set("sendmail_from", "test@example.com");
ini_set("smtp_port", "25"); 

如果此网站托管在您自己的服务器上,您需要下载SendEmail或Mercury才能在本地主机上发送/接收电子邮件。