Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
电子邮件表单.php脚本错误_Php_Html_Forms_Email - Fatal编程技术网

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

电子邮件表单.php脚本错误,php,html,forms,email,Php,Html,Forms,Email,我有一个包含电子邮件表单的脚本,然后我有一个.php脚本,它应该将表单中的输入发送到另一封电子邮件。问题是,当我提交表单时,我会看到以下错误: 警告:邮件:无法连接到127.0.0.1端口25的mailserver,请在php.ini中验证SMTP和SMTP_端口设置,或在第16行使用C:\Program Files x86\EasyHP-DevServer-14.1VC11\data\localweb\scripts\supFormSend.php中的ini_设置 Html脚本: <fo

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

警告:邮件:无法连接到127.0.0.1端口25的mailserver,请在php.ini中验证SMTP和SMTP_端口设置,或在第16行使用C:\Program Files x86\EasyHP-DevServer-14.1VC11\data\localweb\scripts\supFormSend.php中的ini_设置

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

例:


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

将错误粘贴为文本,而不是图像。看起来像本地主机,因此除非您碰巧有本地邮件服务器,否则您需要使用外部邮件服务器。看起来您没有运行邮件服务器。一旦您将站点上载到web服务器,或在计算机上安装邮件服务器,这将得到解决。为了防止出现错误消息,您可以键入@mail,这不会解决错误,但会阻止它打印错误消息。所以没有错误,只是因为它必须在主机面板中才能工作?所以,我不必关心它所造成的错误,它会在主机面板上工作吗?
ini_set("SMTP", "mail.example.com");
ini_set("sendmail_from", "test@example.com");
ini_set("smtp_port", "25");