Jump to content

Adding a 'send to' email


lucidpage
Go to solution Solved by QuickOldCar,

Recommended Posts

I have a bit of php code that sends an email. I would like to add another email recipient to this code, so that the email is sent to BOTH the post author AND the following email address... help@dealfiles.com

 

Yes, this is part of a Wordpress plugin. It's a small part of a large plugin that I have a LOT of time investing in setting up, so I can't just look for an alternate plugin. I really need to get this one to work.

 

Thanks in advance for any and all help with this.

Here is the existing code:

<?php 
              if (get_post_meta( $post->ID, '_listing_contact_form', true) != '') {
  
                  echo do_shortcode(get_post_meta( $post->ID, '_listing_contact_form', true) );
  
              } else {
  
                  $nameError = '';
                  $emailError = '';
 
                 if(isset($_POST['submitted'])) {
 
                 $url = get_permalink();
                 $listing = get_the_title();
 
                 if(trim($_POST['contactName']) === '') {
                     $nameError = 'Please enter your name.';
                     $hasError = true;
                 } else {
                     $name = trim($_POST['contactName']);
                 }
 
                 if(trim($_POST['email']) === '')  {
                     $emailError = 'Please enter your email address.';
                     $hasError = true;
                 } else if (!preg_match("/^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$/i", trim($_POST['email']))) {
                     $emailError = 'You entered an invalid email address.';
                     $hasError = true;
                 } else {
                     $email = trim($_POST['email']);
                 }
 
                 $phone = trim($_POST['phone']);
 
                 if(function_exists('stripslashes')) {
                     $comments = stripslashes(trim($_POST['comments']));
                 } else {
                     $comments = trim($_POST['comments']);
                 }
 
 
                 if(!isset($hasError)) {
                     $emailTo = get_the_author_meta( 'user_email', $post->post_author );
                     if (!isset($emailTo) || ($emailTo == '') ){
                         $emailTo = get_option('admin_email');
                     }
                     $subject = 'Listing Inquiry from '.$name;
                     $body = "Name: $name \n\nEmail: $email \n\nPhone: $phone \n\nListing: $listing \n\nURL: $url \n\nComments: $comments";
                     $headers = 'From: '.$name.' <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
 
                     wp_mail($emailTo, $subject, $body, $headers);
                     $emailSent = true;
                 }
 
             } ?>
Link to comment
Share on other sites

  • Solution

Can't you just add an additional wp_mail() call there?

<?php 
              if (get_post_meta( $post->ID, '_listing_contact_form', true) != '') {
  
                  echo do_shortcode(get_post_meta( $post->ID, '_listing_contact_form', true) );
  
              } else {
  
                  $nameError = '';
                  $emailError = '';
 
                 if(isset($_POST['submitted'])) {
 
                 $url = get_permalink();
                 $listing = get_the_title();
 
                 if(trim($_POST['contactName']) === '') {
                     $nameError = 'Please enter your name.';
                     $hasError = true;
                 } else {
                     $name = trim($_POST['contactName']);
                 }
 
                 if(trim($_POST['email']) === '')  {
                     $emailError = 'Please enter your email address.';
                     $hasError = true;
                 } else if (!preg_match("/^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$/i", trim($_POST['email']))) {
                     $emailError = 'You entered an invalid email address.';
                     $hasError = true;
                 } else {
                     $email = trim($_POST['email']);
                 }
 
                 $phone = trim($_POST['phone']);
 
                 if(function_exists('stripslashes')) {
                     $comments = stripslashes(trim($_POST['comments']));
                 } else {
                     $comments = trim($_POST['comments']);
                 }
 
 
                 if(!isset($hasError)) {
                     $emailTo = get_the_author_meta( 'user_email', $post->post_author );
                     if (!isset($emailTo) || ($emailTo == '') ){
                         $emailTo = get_option('admin_email');
                     }
                     $subject = 'Listing Inquiry from '.$name;
                     $body = "Name: $name \n\nEmail: $email \n\nPhone: $phone \n\nListing: $listing \n\nURL: $url \n\nComments: $comments";
                     $headers = 'From: '.$name.' <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
 
                     wp_mail($emailTo, $subject, $body, $headers);
                     wp_mail('help@dealfiles.com', $subject, $body, $headers);
                     $emailSent = true;
                 }
 
             } ?>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.