1

ユーザー情報を収集するために使用したいフォームがあります。情報を取得して変数に格納するphpがあります。ユーザーが送信ボタンをクリックすると、フォームが送信され、サンキュー ページに正常にリダイレクトされます。なんらかの理由で、期待どおりにメールが届きません。誰かが私がどこで間違っているのか説明できますか.

以下は私のHTMLとPHPファイルです。後で JavaScript の検証を追加します。現時点では、フォームの送信を機能させたいだけです。

PHP

<?php

//This page should not be accessed directly. Need to submit the form.
if(!isset($_POST['submit'])){
echo "ERROR. This page cannot be accessed directly";
}

//Variables from the form
$name               = $_POST['fullname'];
$ageGroup           = $_POST['ageGroup'];
$gender             = $_POST['gender'];
$visit              = $_POST['visit'];
$purposeOfVisit     = $_POST['purposeOfVisit'];
$otherReferrer      = $_POST['otherReferrer'];
$member             = $_POST['member'];
$socialMedia        = $_POST['socialMedia'];
$difficulties       = $_POST['difficulties'];
$easeOfUse          = $_POST['easeOfUse'];
$whatDifficulties   = $_POST['whatDifficulties'];
$specialCondition   = $_POST['specialCondition'];
$browser            = $_POST['browser'];
$preferredFormat    = $_POST['preferredFormat'];
$contentsForWebsite = $_POST['contentsForWebsite'];
$oldContents        = $_POST['oldContents'];
$expectations       = $_POST['expectations'];

$message = "Fullname:"; // will compose later

// Compose email
$email_from = "subash.adikari@gmail.com";
$email_subject = "Infinity User Questionnaire";
$email_body = "You have received a new message from the user $name.\n".
"Here is the message:\n $message".

$to = "subash.adhikari@gmail.com";

$headers = "From: $email_from \r\n";

//Send the email!
mail($to,$email_subject,$email_body,$headers);

//done. redirect to thank-you page.
header('Location: thankyou.html');


if(IsInjected($visitor_email))
{
    echo "Bad email value!";
    exit;
}

// Function to validate against any email injection attempts
function IsInjected($str)
{
  $injections = array('(\n+)',
          '(\r+)',
          '(\t+)',
          '(%0A+)',
          '(%0D+)',
          '(%08+)',
          '(%09+)'
          );
  $inject = join('|', $injections);
  $inject = "/$inject/i";
  if(preg_match($inject,$str))
    {
    return true;
  }
  else
    {
    return false;
  }
}
?>     

必要に応じて、ここからindex.php をダウンロードできます。

どうもありがとう。

4

3 に答える 3

3

mail()これはローカル マシン上にあるため、最初に で設定する必要がありますphp.ini。たとえば、ISP の SMTP サーバーを使用するように構成できます。

[mail function]
SMTP = smtp.isp.net
smtp_port = 25
sendmail_from = me@isp.net

詳細については、PHP ドキュメントを参照してください。

編集: サーバーの 1 つでコードをテストしたところ、期待どおりにメールが送信されました。これにより、機能の構成方法に問題があると思われますmail()

于 2012-04-05T23:45:31.453 に答える
0

問題はホスティング サービスにありました。私は彼らに電話をしなければなりませんでした、そして彼らは私のためにそれを修正しました。

于 2012-04-23T09:27:49.430 に答える
0

http://phpmailer.worxware.com/からPHPMailer を使用してメールを送信することをお勧めします。PHPMailer を使用すると、エラーを追跡したり、HTML および TEXT でメールを送信したり、エンコーディングを変更したり、ワード ワーパーを管理したりできます。

また、誰かが言ったように、スクリプトは直接実行されることを妨げません。ヘッダーは改行文字「\ n」だけで終了し、キャリッジ「\ r」を返さない必要があると思います。

于 2012-04-05T23:42:05.880 に答える