Adding send to email

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]

Here is the existing code:

[php]<?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;
			}

		} ?>[/php]

Since that looks to be for WordPress, I would look for a different plugin that supports multiple recipients. That will be the easiest way to go about this.

I wish I could just select another plugin. Unfortunately, this email form is just a very small part of a larger plugin that has unique functionality, and I have a lot of set up time invested in it.

Any and all help with this would be appreciated.

Simply just add the second email address to the outgoing one. You currently have the “TO” address inside
a variable named $emailTo ! Just add the second one to it. Something like:

$emailTo .= ",[email protected]";

So, if you need to send it to an ADMIN address just add it to the email address. Not complicated.
No real need for another plug-in. Although, as Astonecipher mentioned a different plug-in might
give you a lot more options. Either way works… Good luck…

Sponsor our Newsletter | Privacy Policy | Terms of Service