此联系表格功能齐全吗?
Is this contact form fully function?
填写表格时提示发送成功。所以我需要启用或包含 phpmailer?表格通过 submit.php 发送,但联系表格是 html 页面。我还需要制作联系页面 php 吗? submit.php 的 Chmod 权限是 755。在脚本中我确实有正确的电子邮件地址。我已经安装了 phpmailer,我需要激活它吗?
<?php
// specify your email here
$to = 'example@example.com';
// Assigning data from $_POST array to variables
if (isset($_POST['name'])) { $name = $_POST['name']; }
if (isset($_POST['email'])) { $from = $_POST['email']; }
if (isset($_POST['company'])) { $company = $_POST['company']; }
if (isset($_POST['message'])) { $message = $_POST['message']; }
// Construct subject of the email
$subject = 'Contact Inquery ' . $name;
// Construct email body
$body_message .= 'NAME: ' . $name . "\r\n\n";
$body_message .= 'EMAIL: ' . $from . "\r\n\n";
$body_message .= 'SUBJECT: ' . $company . "\r\n\n";
$body_message .= 'MESSAGE: ' . $message . "\r\n\n";
// Construct headers of the message
$headers = 'From: ' . $from . "\r\n";
$headers .= 'Reply-To: ' . $from . "\r\n";
$mail_sent = mail($to, $subject, $body_message, $headers);
if ($mail_sent == true) { ?>
<script language="javascript" type="text/javascript">
window.alert("Sent Successfuly.");
</script>
<?php } else { ?>
<script language="javascript" type="text/javascript">
window.alert("Error! Please Try Again Later.");
</script>
<?php
} // End else
?>
- 目前,您的表单不需要由 PHP 呈现。因此,它可以保存在 HTML 文件中。
当你说:
The form is being sent via submit.php
我想你想说的是:
The form is being sent to submit.php
如果是这样的话,那我觉得你贴的源码就是
此文件的内容。
- 关于邮件发送,您使用built-in PHP mail()
功能。但是这个函数 use the sendmail binary 需要
安装在您的服务器上。此外,您必须设置适当的
php.ini
文件中的设置 以使您的主机正确
发送电子邮件。
- PHPMailer 是一个很好的替代品,因为它不需要任何外部
依赖项。 simple example 将向您展示基本的使用方法
它。
N.B: 我看到你 PHP 代码很简单,我推断你是初学者,你把这个源代码某个地方,你并不真正理解它。那就对了。你必须从某个地方开始。
但是:
小心这个代码!它接受用户输入并发送它
没有任何完整性检查。我建议您不要在生产环境中部署此代码(如果是用于测试和学习,那就对了)。
看看this answer about PHP user input sanitation。它没有谈论电子邮件发送的卫生。但这可能是了解其基本工作原理的一个很好的起点。那你就得自己搜索了。
填写表格时提示发送成功。所以我需要启用或包含 phpmailer?表格通过 submit.php 发送,但联系表格是 html 页面。我还需要制作联系页面 php 吗? submit.php 的 Chmod 权限是 755。在脚本中我确实有正确的电子邮件地址。我已经安装了 phpmailer,我需要激活它吗?
<?php
// specify your email here
$to = 'example@example.com';
// Assigning data from $_POST array to variables
if (isset($_POST['name'])) { $name = $_POST['name']; }
if (isset($_POST['email'])) { $from = $_POST['email']; }
if (isset($_POST['company'])) { $company = $_POST['company']; }
if (isset($_POST['message'])) { $message = $_POST['message']; }
// Construct subject of the email
$subject = 'Contact Inquery ' . $name;
// Construct email body
$body_message .= 'NAME: ' . $name . "\r\n\n";
$body_message .= 'EMAIL: ' . $from . "\r\n\n";
$body_message .= 'SUBJECT: ' . $company . "\r\n\n";
$body_message .= 'MESSAGE: ' . $message . "\r\n\n";
// Construct headers of the message
$headers = 'From: ' . $from . "\r\n";
$headers .= 'Reply-To: ' . $from . "\r\n";
$mail_sent = mail($to, $subject, $body_message, $headers);
if ($mail_sent == true) { ?>
<script language="javascript" type="text/javascript">
window.alert("Sent Successfuly.");
</script>
<?php } else { ?>
<script language="javascript" type="text/javascript">
window.alert("Error! Please Try Again Later.");
</script>
<?php
} // End else
?>
- 目前,您的表单不需要由 PHP 呈现。因此,它可以保存在 HTML 文件中。
当你说:
The form is being sent via
submit.php
我想你想说的是:
The form is being sent to
submit.php
如果是这样的话,那我觉得你贴的源码就是 此文件的内容。
- 关于邮件发送,您使用built-in PHP mail()
功能。但是这个函数 use the sendmail binary 需要
安装在您的服务器上。此外,您必须设置适当的
php.ini
文件中的设置 以使您的主机正确 发送电子邮件。 - PHPMailer 是一个很好的替代品,因为它不需要任何外部 依赖项。 simple example 将向您展示基本的使用方法 它。
N.B: 我看到你 PHP 代码很简单,我推断你是初学者,你把这个源代码某个地方,你并不真正理解它。那就对了。你必须从某个地方开始。
但是:
小心这个代码!它接受用户输入并发送它 没有任何完整性检查。我建议您不要在生产环境中部署此代码(如果是用于测试和学习,那就对了)。
看看this answer about PHP user input sanitation。它没有谈论电子邮件发送的卫生。但这可能是了解其基本工作原理的一个很好的起点。那你就得自己搜索了。