2

現在、WordPress Web サイトでメール通知を送信する方法を探しています。たとえば、ユーザーがページ A にアクセスすると、バックグラウンドで電子メール通知が送信されます。

WordPress 環境での Web 開発の経験があまりないので、どなたか教えていただけませんか? どこから始めればよいですか?

ありがとう。

編集:

mail() と wp_mail() 関数の両方を試しましたが、どれもうまくいかないようでした。そのページにアクセスしたとき、メールは送信されませんでした。そのページのテンプレートもチェックしましたが、これはデフォルトのテンプレートです。おそらく、間違ったファイルを編集していたのでしょうか??

編集2:

メール機能はおそらくホスティングプロバイダーによってまだ有効になっていないと思います。

4

4 に答える 4

4

これは、html メールを送信する非常に基本的な php コードです。

<?php
if(is_page(123))
{

$fromName = 'Auto email notification system';

$subject = 'Confirmed';

/* Mail Address */
$toAddr = 'me@domain.com'; 
$bccAddr = 'bccperson@domain.com'; 
$fromAddr = 'no-reply@domain.com';
/* End Mail Address */


/* Mail Body */
$msg = '
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
</head>
<body>
my messages about confirmation...
</body>
</html>
';

$msg = wordwrap($msg, 70);
/* End Mail Body */


/* Mail Headers Setup */
$headers = array();
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-type: text/html; charset=utf-8";
$headers[] = "From: ".$fromName." <".$fromAddr.">";
$headers[] = "Bcc: <".$bccAddr.">";
/* End Mail Headers Setup */


mail($toAddr, $subject, $msg, implode("\r\n", $headers));

}
?>

そして、上記のコードをheader.phpファイルの一番下に配置すると、うまくいきました。

すべての提案と助けに感謝します。

于 2012-09-26T09:18:49.087 に答える
1

おそらく、PHP のmail関数でメールを送信し、WordPress のis_page()のような関数でメールを送信するときにページを識別する必要があるでしょう。

<?php 
if(is_page()) :
  mail('email@address.com','My Subject','My Message');
endif;
?>

また、下部にある is_page の「関連」セクションを見てください。メールを送信するページを別の方法で決定したい場合があります。

于 2012-09-25T09:44:45.190 に答える
1

テンプレートの作成は簡単です。新しいページ my-template.php を作成し、このコードを一番上に置きます。

<?php
    /*
    Template Name: My New Template
    */
    ?>

しかし、それはあなたのテーマに依存します。私はあなたのために20を編集しました。テンプレートを作成するためのアイデアが得られます。

<?php
    /*
    Template Name: My New Template
    */

    get_header();

    $headers[] = 'From: Me Myself <me@example.net>';
    $headers[] = 'Cc: Aravind B Codex <abc@wordpress.org>';
    $headers[] = 'Cc: iluvwp@wordpress.org'; // note you can just use a simple email address
?>

<?php 
if(is_page()) :
    wp_mail( $to, $subject, $message, $headers );
endif;
?>


<div id="container">
    <div id="content" role="main">

    <?php
    /* Run the loop to output the page.
     * If you want to overload this in a child theme then include a file
     * called loop-page.php and that will be used instead.
     */
    get_template_part( 'loop', 'page' );
    ?>

    </div><!-- #content -->

</div><!-- #container -->

メールコードを入れてください。テンプレートディレクトリに保存します。

管理パネルに移動し、ページを追加/編集します。ページの右側にオプション (テンプレート) があります。テンプレートがドロップダウンに表示されます。テンプレートを選択してページを保存する

于 2012-09-25T11:34:36.100 に答える
1

Hey @woodykiddy ページのテンプレートを作成し、このコードをページに挿入します。この条件は、ページが読み込まれるたびに true を返します。

// Example using the array form of $headers
// assumes $to, $subject, $message have already been defined earlier...

$headers[] = 'From: Me Myself <me@example.net>';
$headers[] = 'Cc: Aravind B Codex <abc@wordpress.org>';
$headers[] = 'Cc: iluvwp@wordpress.org'; // note you can just use a simple email address

<?php 
if(is_page()) :
    wp_mail( $to, $subject, $message, $headers );
endif;
?>

http://codex.wordpress.org/Function_Reference/wp_mail

これがあなたを助けることを願っています。

于 2012-09-25T10:28:50.507 に答える