javascript - PHP 发送邮件不起作用,价值索引无法访问
问题描述
我用post和action方法来发送邮件。我尝试通过运行测试 PHP 从托管服务器发送短邮件。它正在工作。将其与 HTML 表单合并后不起作用,并且还会给出错误未定义的索引。这是代码的摘要。
HTML 文件:
<form id="msform" action="./php/mailer.php" name="step1" method="POST">
<fieldset>
<h2 class="fs-title">Fillup basic Information</h2>
<h3 class="fs=subtitle">This is step 1</h3><br>
<input type="text" name="fname" placeholder="First Name" required/>
<input type="text" name="lname" placeholder="Last Name" required/>
<input type="button" name="next" class="next action-button" value="Next" onclick="return validateStep1()"/>
</fieldset>
</from>
PHP 文件:
<?php
if(isset($_POST['next']))
{
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$msg="Hello My Name is $fname $lname . My Company is $company which is located in $address1 . The Second address is $address2. I live in $city city, $state state, $zip zip, $country.
My Phone number is $tel. My Fax number is $fax. My email is $email. I want to donate $other. My Custom Donate is $otherDonation. I want to donate regular=$regulardonate for $dollar dollar
per $months";
mail("x@gmail.com","Donation",$msg);
}
?>
JS 文件:
function validateStep1()
{
var fname =document.forms["step1"]["fname"];
var lname =document.forms["step1"]["lname"];
if (fname.value == "")
{
window.alert("Please enter your first name.");
fname.focus();
return false;
}
if (lname.value == "")
{
window.alert("Please enter your Last name.");
lname.focus();
return false;
}
window.open('./second.html', '_self');
return true;
}
我在 GitHub 上的 Live 表单,您可以查看 - https://tamzid958.github.io/multipage_form/
解决方案
您表单中的 PHP 文件无法作为https://tamzid958.github.io/multipage_form/工作,因为主机根本不解析 PHP。此托管仅适用于静态页面,例如 HTML、JS、CSS。
您需要将代码放在支持 PHP 的主机上。
推荐阅读
- javascript - 将回调代码改进为异步等待猫鼬
- javascript - 如何使用带有 0x 的 javascript 将 Double 转换为十六进制
- javascript - WebHID API:重新连接设备
- java - Android Java OutputStream将整个文件缓冲成流
- flutter - 颤动:不导航到另一个页面
- windows - 在 Perl 脚本中无法将目录添加到存档
- html - CSS自动隐藏/显示每2秒
- r - 我们如何拆分字符串并提取圆括号之间的文本
- javascript - 如何制作不同屏幕尺寸的响应式同位素画廊插件?
- r - 如何在输出中使用反应式表达式的结果