有一个问题是能够使用PHP发送邮件我查看了我的代码,无法找到我出错的地方。用我的html编辑进行编辑。
<?php
if (isset($_POST['primaryemail'])){
$first_name = $_POST['first_name'];
$phone_number = $_POST['phone_number'];
$phone_numbertwo = $_POST['phone_numbertwo'];
$primaryemail = $_POST['primaryemail'];
if (!empty($primaryemail)) {
$to = 'testemail@gaming.com';
$subject = 'Jobsite Form Submitted';
$body = "Submitted by: " . $first_name . "Phone number: " . $phone_number . "Secondary phone number: " . $phone_numbertwo;
$headers = 'From:' . $primaryemail;
mail($to, $subject, $body, $headers);
}
}
?>
<form name="jobsiteform" class="jobsiteform" method="POST" action="">
<h2>Contact Information</h2>
<h4>Primary Contact Information</h4>
<br>
<label>Full Name: </label>
<input type="text" name="first_name" id="first_name" maxlength="70" placeholder="First & Last" required>
<br><br>
<label>Phone Number: </label>
<input type="text" name="phone_number" id="phone_number" class="phone" maxlength="13" placeholder="(xxx) xxx-xxxx" required>
<br><br>
<label>Secondary Phone Number: </label>
<input type="text" name="phone_numbertwo" id="phone_numbertwo" class="phone" maxlength="13" placeholder="Optional">
<br><br>
<label>E-mail: </label>
<input type="email" name="email" maxlength="100" id="primaryemail" placeholder="e.g. first.last@domain.com" required>
<br>
答案 0 :(得分:3)
name=""
而不是id=''
您需要修改html,并将ID
设置为主要电子邮件字段中的Name
。名称参数由Post请求使用到PHP而不是ID(通常由javascript使用)。
<input type="email" name="primaryemail" maxlength="100" id="primaryemail" placeholder="e.g. first.last@domain.com" required>
因此,由于此行,您的php脚本永远不会执行,因为post值设置为键$_POST['email']
而不是$_POST['primaryemail']
因此未设置。
if (isset($_POST['primaryemail'])){
这就是为什么在最后做一个其他的echo 'error: post email not sent';
答案 1 :(得分:1)
将您的PHP代码放在extern文件中,在action="path to file"
中添加该文件的路径,并在<form>
中添加一个提交按钮。示例:<input type="submit" value="Send">
。