web-dev-qa-db-fra.com

Lors de la soumission du formulaire, comment envoyer 2 courriels à différents utilisateurs

J'ai créé un formulaire php personnalisé et sur sa soumission, un courrier électronique est envoyé à l'utilisateur, mais je souhaite également envoyer un courrier électronique à l'administrateur afin de le tenir à jour sur les soumissions de formulaire sur le site Web à l'aide de wp_mail.

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

Et le traiter:

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, tout ce que vous avez à faire est d’ajouter du code pour le deuxième courrier électronique au même endroit:

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
Krzysiek Dróżdż