wp mail - On form submission how to send 2 email to different users

admin2025-04-22  0

I have created a custom php form and on its submission email is sent to user but i want to send email to admin as well to keep admin up-to-date about form submissions on website using 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>

And processing it:

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);
}

I have created a custom php form and on its submission email is sent to user but i want to send email to admin as well to keep admin up-to-date about form submissions on website using 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>

And processing it:

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);
}
Share Improve this question edited Dec 5, 2018 at 22:28 Krzysiek Dróżdż 25.6k9 gold badges53 silver badges74 bronze badges asked Dec 5, 2018 at 22:05 Wish CodexWish Codex 134 bronze badges 4
  • Hi. Thanks for your question. Could you update it and post your code? It will make helping you a lot easier :) – Krzysiek Dróżdż Commented Dec 5, 2018 at 22:08
  • @KrzysiekDróżdż i have updated my question please have a look – Wish Codex Commented Dec 5, 2018 at 22:25
  • Great, thanks. Should both emails be the same? – Krzysiek Dróżdż Commented Dec 5, 2018 at 22:27
  • Nope, Both emails have different content one for admin(It contains a message to notify admin new user submitted form on website) and other one for user – Wish Codex Commented Dec 5, 2018 at 22:29
Add a comment  | 

1 Answer 1

Reset to default 0

OK, so all you need to do is to add code for second email in the same place:

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
    );
}
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1745297196a295043.html

最新回复(0)