Jump to content

Adding a 'send to' email


lucidpage

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... [email protected]

 

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
https://forums.phpfreaks.com/topic/292479-adding-a-send-to-email/
Share on other sites

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('[email protected]', $subject, $body, $headers);
                     $emailSent = true;
                 }
 
             } ?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.