1

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 jobs@xyz.com' . 
wp_mail($to,$subject,$content,$headers);
}
  • Hi. Thanks for your question. Could you update it and post your code? It will make helping you a lot easier :) – Krzysiek Dróżdż Dec 5 '18 at 22:08
  • @KrzysiekDróżdż i have updated my question please have a look – Wish Codex Dec 5 '18 at 22:25
  • Great, thanks. Should both emails be the same? – Krzysiek Dróżdż Dec 5 '18 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 Dec 5 '18 at 22:29
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 jobs@xyz.com' . "\r\n";
    wp_mail( $to, $subject, $content, $headers );

    // And here goes second email:
    $admin_email = get_option( 'admin_email' );
    $headers = 'From: Job Post at jobs@xyz.com' . "\r\n";
    wp_mail(
        $admin_email,
        'Subject of second email',
        'Message content',
        $headers
    );
}
  • didn't worked only sends email to user – Wish Codex Dec 5 '18 at 22:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.