2

単純なphpメール連絡フォームが機能するのに問題があります。エラーは生成または返されませんが、電子メールを受信して​​いません。

これは私のフォームですhttp://bitstream.ca/beta2/contact.html

そして私が使用しているphp(もちろん私の適切な電子メールで)

誰かが以下のフォームコードでエラーを見ることができますか?試すべき一般的なデバッグ手順は何ですか?前もって感謝します!

<?php 
$errors = '';
$myemail = 'foo@foo.foo';//<-----Put Your email address here.
if(empty($_POST['name'])  || 
   empty($_POST['email']) || 
   empty($_POST['message']))
{
    $errors .= "\n Error: all fields are required";
}

$name = $_POST['name']; 
$email_address = $_POST['email']; 
$message = $_POST['message']; 

if (!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z {2,3})$/i", $email_address))
  {
  $errors .= "\n Error: Invalid email address";
  }
  if( empty($errors))
  {
    header('Location: contact-form-thank-you.html');
  } 
 ?>
<!DOCTYPE HTML> 
<html>
 <head>
 <title>Contact form handler</title>
 </head>
<body>
<!-- This page is displayed only if there is some error -->
<?php
   echo nl2br($errors);
?>
 </body>
</html>
4

3 に答える 3

0

実際に電子メールを送信するには、mail()関数(または他のメーリングPEARクラスなど)への呼び出しを追加する必要があります。ここを見てください:http://php.net/manual/en/function.mail.php

于 2012-04-22T20:17:17.733 に答える
0

ifあなたのステートメントの間にこれを挿入してください:

if(empty($errors)) {
    mail($email,$subject,$message,$headers);
    header('Location: contact-form-thank-you.html');
} 
于 2012-04-22T20:19:13.990 に答える
0

あなたが試すことができます

<?php
$errors = array ();
$myemail = 'foo@foo.foo'; // <-----Put Your email address here.
$name = $_POST ['name'];
$to = $_POST ['email'];
$message = $_POST ['message'];
$subject = "Sample Email";
$headers = "From: $myemail" . "\r\n" . "Reply-To: $myemail" . "\r\n" . 'X-Mailer: PHP/' . phpversion ();

if (empty ( $_POST ['name'] ) || empty ( $_POST ['email'] ) || empty ( $_POST ['message'] )) {
    $errors [] = "Error: all fields are required";
}

if (! preg_match ( "/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z {2,3})$/i", $to )) {
    $errors [] = "Error: Invalid email address";
}

if (count ( $errors ) == 0) {
    if (@mail ( $to, $subject, $message, $headers )) {
        $errors [] = "Can't send Email";
    }
    header ( 'Location: contact-form-thank-you.html' );
}
?>
<!DOCTYPE HTML>
<html>
<head>
<title>Contact form handler</title>
</head>
<body>
    <!-- This page is displayed only if there is some error -->
<?php
echo implode ( "<br />", $errors );
?>
 </body>
</html>
于 2012-04-22T20:28:51.047 に答える