Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Contact Form Send to Admin Email WordPress

  • SOLVED

I have a WordPress contact form. The PHP for sending the form can be found here here: [[LINK href="http://snippi.com/s/590n1sq"]]http://snippi.com/s/590n1sq[[/LINK]]

The HTML can be found here: [[LINK href="http://snippi.com/s/ymkijx8"]]http://snippi.com/s/ymkijx8[[/LINK]]

The form sends emails to [email protected] on line 11. I need to replace this with the email generated by <?php echo get_option('admin_email'); ?>

Please note the form must redirect to /thanks, not insert.php!

Answers (2)

2014-02-27

Luis Abarca answers:

Contact form 7 will help you with that in a better way.

But if you want to use that script, tell us, where is the location of your script in the WordPress root folder?


siouxfan45 comments:

Luis, I have updated the question. The script is in the template directory's scripts folder (<?php echo get_template_directory_uri(); ?>/scripts/insert.php">)


Luis Abarca comments:

Well, to use WordPress function, you need to load it


<?php

// In your form procesor script (insert.php)

require_once('../../../wp-load.php');



http://snippi.com/s/zqgg2wg


siouxfan45 comments:

Kyle, that code did not work. The form didn't send and I was redirected to insert.php.


Luis Abarca comments:


<?php
<strong>// Load WordPress</strong>
require_once('../../../wp-load.php');

$this_form_spam = $_POST['this_title'];
if ($this_form_spam == "")
{
// Get values from form
$name=$_POST['name'];
$phone=$_POST['phone'];
$email=$_POST['email'];
$message=$_POST['message'];

$to = get_option('admin_email');
$subject = "Potential Client Lead";
$message = " Name: " . $name . "\r\n Phone: " . $phone . "\r\n Email: " . $email . "\r\n Message: " . $message;

$from = "FirmFlip";
$headers = "From:" . $email . "\r\n";
$headers .= "Content-type: text/plain; charset=UTF-8" . "\r\n";

if(@mail($to,$subject,$message,$headers))
{
header('Location: /thanks/'); <strong>// Use header for redirections</strong>

}else{
echo "Error! Please try again.";
}
} else {

}


siouxfan45 comments:

Luis,

I tried your code and it is not working. Am I missing something here? You can test your code here: [[LINK href="http://themeforward.com/demo2/?page_id=3118"]]http://themeforward.com/demo2/?page_id=3118[[/LINK]]


Luis Abarca comments:

Sorry, i miss the script/ folder


<?php
// Load WordPress
require_once('../../../../wp-load.php');

$this_form_spam = trim($_POST['this_title']);

if ( empty($this_form_spam) ) {
// Get values from form
$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$message = $_POST['message'];

$to = get_option('admin_email');

$subject = 'Potential Client Lead';

$message = " Name: $name\r\n Phone: $phone \r\n Email: $email \r\n Message: $message";

$from = "FirmFlip";

$headers = "From: $email\r\n";

$headers .= "Content-type: text/plain; charset=UTF-8\r\n";

if(@mail($to, $subject, $message, $headers)) {
header('Location: /thanks/'); // Use header for redirections
} else {
echo 'Error! Please try again.';
}
} else {
// @TODO:
}


Luis Abarca comments:

Here is the original code.

[[LINK href="https://gist.github.com/luisabarca/9243710"]]https://gist.github.com/luisabarca/9243710[[/LINK]]

2014-02-27

Kyle answers:

Is this what you are looking for http://pastie.org/8798544

Wasn't sure what you meant be the redirect


siouxfan45 comments:

Kyle,

Take a look here (this is with your code running) http://themeforward.com/demo2/?page_id=3118

When you fill out the form and send with your code, the user is redirected to insert.php and the form is not sent.

Here is the HTML as well: http://snippi.com/s/ymkijx8