1

I am using ACF options to save and email address for contact forms. Using Wordpress multi-site I can set who I want the forms to go to through the options panel. The form is sending out the auto responder, but it is not submitting to the saved email address.

<?php
$contact_form_email = get_field('contact_form_email','options');
$cyber_to = array($contact_form_email);
# CyberMark Subject Line
$cyber_subject  = $s." Form Submission";

# Headers of email
$cyber_headers  = "From: " . strip_tags('[email protected]') . "\r\n";
$cyber_headers .= "MIME-Version: 1.0" . "\r\n";
$cyber_headers .= "Content-Type: text/html; charset=ISO-8859-1" . "\r\n";

# CyberMark message
$cyber_msg = '<table width="500" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>Name:</td>
<td style="margin-left: 5px;">'.$n.'</td>
</tr>
<tr>
<td>Email:</td>
<td style="margin-left: 5px;">'.$e.'</td>
</tr>
<tr>
<td>Phone:</td>
<td style="margin-left: 5px;">'.$t.'</td>
</tr>
<tr>
<td>Message:</td>
<td style="margin-left: 5px;">'.$m.'</td>
</tr>
</table>';

# Loop through all email recipients
foreach($cyber_to as $cyber_email)
{
    mail($cyber_email,$cyber_subject,$cyber_msg,$cyber_headers);
}

?>

1 Answer 1

1

I guess from your problem that the PHP file processing the form is just inside a WP folder, its not really running within wordpress "ambient".

You need to actually load WP inside the file like this:

require($_SERVER['DOCUMENT_ROOT'].'/wp-load.php');

This will load everything-wordpress for you to use in that file, including get_field(). ;)

Sign up to request clarification or add additional context in comments.

2 Comments

This worked and the form processes! Thank you. My issue now is its not going to the email in the acf options area. I updated the code to: $contactEmail = get_field('contact_email', 'options'); $cyber_to = $contactEmail;
I never used the options page from ACF, but it seems to be saved as a regular option in wp_options. The online quick help does not show any use with get_field(). Try the regular way to get options in WP, get_option( 'your_option').

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.