wp_mail() issue

Hey there,

I am using a form to submit an email to the end user. Since I have set up my site as a theme, i want to use a string to hold the email for the site. This can then be used in the footer, and to send emails.

So I have set up a string $site_email = get_option(‘site_email’); where ‘site_email’ is an option in a plugin I have created called Theme options. You use it to enter various data to the database: address, google mail map html data, and email.

Ok, so if I echo the string $site_email, throughout the website, it works fine. And even if I echo it on the form, it works fine, but when i use the string in wp_mail() like this:


wp_mail($site_email, $subject, $message, $headers);

The email never reaches my inbox. However, if I actually type in the email address into the function:


wp_mail('me@mydomain.com', $subject, $message, $headers);

I get the email I wanted, even though echo $site_email; will return the correct email address.

Does anyone have an idea what’s going on here?

Many thanks,
Mike

I don’t know anything about wp_mail, but maybe it is only meant to pick up on variables that are set on the page itself. So I would try something like this:

$site_email = get_option(‘site_email’);
wp_mail($site_email, $subject, $message, $headers);

(I really know nothing about this stuff, but since no one has answered yet I thought I’d chip in.)

Thanks Ralph,

I actually define $site_email in my post function:


if(!isset($hasError)) {
		$site_email = get_option('site_email');
		$cf_number = trim($_POST['cf_number']);
		$subject = 'Booking from the website';
		$body = "Tel: $cf_number \
PAX: $pax \
Date: $cf_date \
Time: $cf_time \
Message: $cf_message";
		$headers = 'From:' .$cf_name. '<'.$cf_email.'>' . "\\r\
" . 'Reply-To: ' . $cf_email;

		wp_mail($site_email, $subject, $body, $headers);
		$emailSent = true;
	}

and like I said, if I echo the string on the same page, it print’s out just fine.

Appreciate the help though. :slight_smile:

Cheers,
Mike

When you check the echoed string, does it look fine in the page source? Also try var_dump() instead of echo.

Yeah, source code looks good. I’ll give var_dump() a try. Thanks again Saul. :slight_smile: