私はこのフォームを書きましたが、完全に機能します。メールは問題なく送信されます。しかし、送信後、エラーになります。そのため、フォームを送信した人は壊れていると思いますが、実際にはフォームを送信します。私がやろうとしているのは、メールが送信された後にフォームが thanks.asp に送信された後にリダイレクトすることだけです。
どんな助けでも大歓迎です。
<?php
$name = trim($_POST['name']);
$company = $_POST['company'];
$email = $_POST['email'];
$comments = $_POST['comments'];
$site_owners_email = 'support@macnx.com'; // Replace this with your own email address
$site_owners_name = 'Landin'; // replace with your name
if (strlen($name) < 2) {
$error['name'] = "Please enter your name";
}
if (!preg_match('/^[a-z0-9&\'\.\-_\+]+@[a-z0-9\-]+\.([a-z0-9\-]+\.)*+[a-z]{2}/is', $email)) {
$error['email'] = "Please enter a valid email address";
}
if (strlen($comments) < 3) {
$error['comments'] = "Please leave a comment.";
}
if (!$error) {
require_once('phpMailer/class.phpmailer.php');
$mail = new PHPMailer();
$mail->From = $email;
$mail->FromName = $name;
$mail->Subject = "Website Contact Form";
$mail->AddAddress($site_owners_email, $site_owners_name);
$mail->Body = $email . $company . $comments;
// GMAIL STUFF
$mail->Mailer = "smtp";
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->SMTPSecure = "tls";
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "inquiry@getgearhead.com"; // SMTP username
$mail->Password = "..."; // SMTP password
$mail->Send();
header("Location: http://www.macnx.com/noflash/thanks.asp");
}
?>