it-swarm.com.de

Beim Absenden des Formulars erfahren Sie, wie 2 E-Mails an verschiedene Benutzer gesendet werden

Ich habe ein benutzerdefiniertes PHP-Formular erstellt und bei der Übermittlung wird eine E-Mail an den Benutzer gesendet. Ich möchte jedoch auch eine E-Mail an den Administrator senden, um den Administrator über Formularübermittlungen auf der Website mit wp_mail auf dem Laufenden zu halten.

<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>

Und verarbeite es:

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

Alles, was Sie tun müssen, ist Code für die zweite E-Mail an derselben Stelle hinzuzufügen:

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