我已经在这个讨论PHP邮件()的论坛上查了很多帖子,但我还没有能够解决我的问题。我尝试做的只是从表单中读取数据,我使用javascript进行一些错误验证,然后将其发送到php,然后将信息通过电子邮件发送到指定的电子邮件。它不会发送电子邮件。我做错了什么?
如果有帮助,请点击该网站的链接... American Music Academy
这是HTML
<form onsubmit="return validateForm(this)" action="../php/sign-up-form.php" method="post" id="signup">
<div id="form-error-message">
<p></p>
</div>
<input type="text" id="fname" name="fname" placeholder="First Name" maxlength="20" required />
<input type="text" id="lname" name="lname" placeholder="Last Name" maxlength="30" required />
<input type="email" id="email" name="email" placeholder="Email Address" maxlength="35" required />
<div id="telId">
<p>Phone:</p><p>(</p><input type="tel" id="phone1" name="phone1" placeholder="XXX" maxlength="3" required /><p>)</p>
<input type="tel" id="phone2" name="phone2" placeholder="XXX" maxlength="3" required /><p>-</p>
<input type="tel" id="phone3" name="phone3" placeholder="XXXX" maxlength="4" required />
</div>
<select id="primaryInstrument" name="primaryInstrument">
<option value="default">What do you want to play?</option>
<option value="singing">Singing</option>
<option value="piano">Piano</option>
<option value="guitar">Guitar</option>
<option value="drums">Drums</option>
<option value="bassguitar">Bass Guitar</option>
<option value="flute">Flute</option>
<option value="clarinet">Clarinet</option>
<option value="bassoon">Bassoon</option>
<option value="saxophone">Saxophone</option>
<option value="trumpet">Trumpet</option>
<option value="trombone">Trombone</option>
<option value="frenchhorn">French Horn</option>
</select>
<select id="secondaryInstrument" name="secondaryInstrument">
<option value="default">Do you want to play anything else?</option>
<option value="singing">Singing</option>
<option value="piano">Piano</option>
<option value="guitar">Guitar</option>
<option value="drums">Drums</option>
<option value="bassguitar">Bass Guitar</option>
<option value="flute">Flute</option>
<option value="clarinet">Clarinet</option>
<option value="bassoon">Bassoon</option>
<option value="saxophone">Saxophone</option>
<option value="trumpet">Trumpet</option>
<option value="trombone">Trombone</option>
<option value="frenchhorn">French Horn</option>
</select>
<textarea id="comments" name="comments" placeholder="Add comments you have here... (300 characters max)" maxlength="300"></textarea>
<div id="agreement-div">
<input type="checkbox" id="agree" name="agree" value="yes" required />
<p>You acknowledge that you have read our <a href="privacy-policy.html">Privacy Policy</a> and agree to its terms.</p>
<button type="submit" form="signup" value="Submit">Submit</button>
<button type="reset" value="Reset">Clear</button>
</div>
<h3>Call us for a Live Instrument Demonstration over the phone!</h3>
</form>
这是PHP
<?php
/* Takes the information from the sign up form and sends an email to thisisarealemail@butidontwanttoputitonaforum.com */
$agreement = $_POST['agree'];
if(strtolower($agreement) == "yes") {
$firstName = $_POST['fname'];
$lastName = $_POST['lname'];
if($_POST['email'] !== null || $_POST['email'] !== "") {
$email = $_POST['email'];
} else {
$email = "N/A";
}
$phone = $_POST['phone'];
$phoneSymbols = array("-", "(", ")");
$phone = str_replace($phoneSymbols, "", $phone);
$pInstrument = $_POST['primaryInstrument'];
if($_POST['secondaryInstrument'] !== null || $_POST['secondaryInstrument'] !== "") {
$sInstrument = $_POST['secondaryInstrument'];
} else {
$sInstrument = "N/A";
}
if(strlen($_POST['comments']) <= 300) {
$comments = $_POST['comments'];
} else {
$comments = "";
}
$emailContents = "Someone has recently contacted you about Music Lessons from the American Music Academy website.";
$emailContents .= "<br />First Name: ".$firstName."<br />Last Name: ".$lastName."<br />Email: ".$email;
$emailContents .= "<br />Phone: ".$phone."<br />Wants to learn how to play ".$pInstrument;
$emailContents .= "<br />Is also interested in ".$sInstrument."<br />Comments: ".$comments;
// Send email
$recipient = "thisisarealemail@butidontwanttoputitonaforum.com";
$subject = "New Student - American Music Academy";
$headers = 'From: arealemail@realemail.com' . " " .
'Reply-To: arealemail@realemail.com' . " " .
'X-Mailer: PHP/' . phpversion();
$mailsend = mail($recipient, $subject, $emailContents, $headers);
}?>