web-dev-qa-db-ja.com

フォーム送信時に異なるユーザーに2通のEメールを送信する方法

カスタムphpフォームを作成し、その送信時にユーザーに電子メールを送信しましたが、管理者にも電子メールを送信して、管理者がwp_mailを使用してWebサイト上のフォーム送信について最新の状態に保ちたいです。

<form action="<?php echo get_permalink() ?>" method="post" enctype="multipart/form-data">
    <input type="text" name="ch_name" placeholder="Name*" value="" required>
    <input type="text" name="ch_phone_num" placeholder="Phone*" value="" required>
    <input type="email" name="ch_email" placeholder="Email*" value="" required>
    <input type="text" name="ch_company" placeholder="Company*" value="" required>
    <input type="text" name="ch_job_title" placeholder="Job Title*" value="" required>
    <input type="file" name="upload" value="">
    <input type="submit" name="submit" id="submitted">
</form>

そしてそれを処理する:

if(isset($_POST['submit'])) {
$ch_name = $_POST['ch_f_name'];
$ch_phone_num = $_POST['ch_phone_num'];
$ch_email = $_POST['ch_email'];
$ch_company = $_POST['ch_company'];
$ch_job_title = $_POST['ch_job_title'];
$to = $ch_email;
$subject = "Thank you for job Submission ";
$content = "'.$ch_name.'";
        $headers  = 'MIME-Version: 1.0' . "\r\n";
        $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
        $headers .= 'From: Job Post at [email protected]' . 
wp_mail($to,$subject,$content,$headers);
}
1
Wish Codex

OK、だからあなたがする必要があるのは同じ場所に2番目の電子メールのためのコードを追加することだけです:

if ( isset( $_POST['submit']) ) {
    $ch_name = $_POST['ch_f_name'];
    $ch_phone_num = $_POST['ch_phone_num'];
    $ch_email = $_POST['ch_email'];
    $ch_company = $_POST['ch_company'];
    $ch_job_title = $_POST['ch_job_title'];
    $to = $ch_email;
    $subject = "Thank you for job Submission ";
    $content = "'.$ch_name.'";

    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    $headers .= 'From: Job Post at [email protected]' . "\r\n";
    wp_mail( $to, $subject, $content, $headers );

    // And here goes second email:
    $admin_email = get_option( 'admin_email' );
    $headers = 'From: Job Post at [email protected]' . "\r\n";
    wp_mail(
        $admin_email,
        'Subject of second email',
        'Message content',
        $headers
    );
}
0