0

私はWordPressが初めてです。静的ページ contact.php を作成します。連絡先ページには、連絡先フォームがあるので、ユーザーは私に連絡します。ユーザーが送信ボタンをクリックすると、index.php に移動し、電子メール配信の成功を促すプロンプトが表示されます。

これはcontact.phpのコードです

<form class="form" method="post" action="/send-email.php">

    <p class="name">
        <input type="text" name="name" id="name" placeholder="Enter your name" size="40" />
        <label for="name">Name</label>
    </p>

    <p class="email">
        <input type="text" name="email" id="email" placeholder="mail@example.com"   size="40" />
        <label for="email">Email</label>
    </p>

    <p class="web">
        <input type="text" name="telephone" id="telephone" placeholder="000-000-000" size="40" />
        <label for="telephone">Telephone</label>
    </p>        

    <p class="text">
        <label for="message">Message</label>
        <textarea name="message" placeholder="Write something to us" cols="40" rows="5" /></textarea>
    </p>

    <p class="submit">
        <input type="submit" value="Send" />
        <input type="reset" value="Cancel" />
    </p>

</form>

send-email.php

<?php
$ToEmail = 'sample@sample.com';
$EmailSubject = 'Contact Form';
$mailheader = "From: " . $_POST["email"] . "\r\n";
$mailheader .= "Reply-To: " . $_POST["email"] . "\r\n";
$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";
$MESSAGE_BODY = " <strong>Name:</strong> " . $_POST["name"] . "";
$MESSAGE_BODY .= "<br> <strong>Email:</strong> " . $_POST["email"] . "";
$MESSAGE_BODY .= "<br> <strong>Telephone:</strong> " . $_POST["telephone"] . "";
$MESSAGE_BODY .= "<br><br> <strong>Message:</strong> " . nl2br($_POST["message"]) . "";
mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die("Failure");


/* echo "<pre>";
  print_r($MESSAGE_BODY);
  echo "<pre>"; */

header("Location: /index");

しかし、それは送信されていません。URL は www.site.com/send-email.php のようになります。

ここで何が欠けていますか?何か案は?よろしくお願いします。ありがとう。

4

2 に答える 2

0
<form class="form" method="post" action="index.php">

    <p class="name">
        <label for="name">Name</label>
        <input type="text" name="name" id="name" placeholder="Enter your name" size="40" />

    </p>

    <p class="email">
         <label for="email">Email</label>
        <input type="text" name="email" id="email" placeholder="mail@example.com"   size="40" />

    </p>

    <p class="web">
         <label for="telephone">Telephone</label>
        <input type="text" name="telephone" id="telephone" placeholder="000-000-000" size="40" />

    </p>        

    <p class="text">
        <label for="message">Message</label>
        <textarea name="message" placeholder="Write something to us" cols="40" rows="5" /></textarea>
    </p>

    <p class="submit">
        <input type="submit" name="submit" value="Send" />
        <input type="reset" value="Cancel" />
    </p>

</form>

そしてあなたのindex.php

<?php
if(isset($_POST['submit'] == 'Send')) {
    $ToEmail = 'sample@sample.com';
    $EmailSubject = 'Contact Form';
    $mailheader = "From: " . $_POST["email"] . "\r\n";
    $mailheader .= "Reply-To: " . $_POST["email"] . "\r\n";
    $mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";
    $MESSAGE_BODY = " <strong>Name:</strong> " . $_POST["name"] . "";
    $MESSAGE_BODY .= "<br> <strong>Email:</strong> " . $_POST["email"] . "";
    $MESSAGE_BODY .= "<br> <strong>Telephone:</strong> " . $_POST["telephone"] . "";
    $MESSAGE_BODY .= "<br><br> <strong>Message:</strong> " . nl2br($_POST["message"]) . "";
    $status = mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die("Failure");

}

if($status){
    echo "your success message";
}
 ?>

これを試して

もう一つ

これをワードプレスで使用しているため、ワードプレスのwp_mail 関数を使用することをお勧めします

于 2013-09-13T04:41:33.597 に答える
0

die("Failure")画面に出力する代わりに、「失敗」メッセージを開始してログに記録しているように聞こえます。mail()または、mail モジュールがインストールされていないため、関数が何であるかさえわからないというエラーが発生しています。よくわかりません。

私の推測では、あなたのサーバーはまだメールを適切に送信するように設定されていません。独自のサーバーを実行している場合、これは複雑な設定になる可能性があります。共有サーバーを使用している場合は、ホストがあまり良くない場合を除いて、既にセットアップされている必要があります。

いずれにせよ、WordPress で実行している場合は、WordPress 自体を作成した人々によってJetpackプラグインをインストールすることをお勧めします。カーソルを数回クリックするだけでページに連絡先フォームを追加する機能が含まれています。

そのフォームからメールが送信されない場合は、質問で提供した情報の範囲を超えた問題があります。

于 2013-09-13T04:33:04.610 に答える