電子メール フィールドを検証しようとしています。有効な場合はフォームを送信します。しかし、フォームをサーバーに送信するとエラーが発生します。送信ボタンで送信すると正常に動作します。
<script>
function ValidateEmail(inputText)
{
var mailformat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
if(inputText.value.match(mailformat))
{
document.form1.submit();
}
else
{
alert("You have entered an invalid email address!");
document.form1.email.focus();
return false;
}
}
</script>
<form action="mailer.php" id="form1" name="form1" method="POST">
<input type="text" size="19" name="name"/>
<input type="text" size="19" name="phone"/>
<input type="text" size="19" name="email"/>
<a onclick="ValidateEmail(document.form1.email)" href="#">Submit</a>
</p>
</form>
<?php
if(isset($_POST['submit'])) {
$to = "marshal@smedia.ca";
$to2 = $_POST['email'];
$subject = "Lead Gen";
$subject2 = "Coupon2";
$first_field = $_POST['name'];
$email_field = $_POST['email'];
$phone_field = $_POST['phone'];
$headers .= "Content-type: text/html\r\n";
$headers .= 'From: Nurray GM <welcome@mycompany.com>' . "\r\n";
$body = "
From: $first_field \n
E-Mail: $email_field\n
Phone Number: $phone_field\n ";
$body2 = "
<html>
<body bgcolor='#DCEEFC'>
<p>Hello $first_field,</p>
<p>Thank you for applying for pre approval. balbalblah.</p>
<img src='www.smedia.ca/clients/leadgen/murray/coupon.jpg' width='500px' height='200px' />
</body>
</html>
";
mail($to, $subject, $body, $headers);
mail($to2, $subject2, $body2, $headers );
header("Location: http://www.smedia.ca/clients/leadgen/murray/redirect.html");
} else {
echo "Sorry - something seems to be wrong. Your message was not sent";
}
?>