Jump to content

Emailing form submission to user also?


Morgan19
 Share

Recommended Posts

Hey all,

Disclaimer: I know next to nothing about PHP, but I have successfully been using PHP Freebies' Form Mailer for years to create clients' simple web forms.

One client recently asked a request that I'm not sure how to handle, though, which is where I could use some help... The info submitted via a form gets emailed to the address listed in the form's config files, but they also want the submission to get sent to whatever email the user enters in the form's email field as well– a copy for the user, basically. I'm wondering if that's an easy thing to specify.

This is the line from the config.php that tells the form submission where to get emailed:

// email address where form contents will be mailed

// to be emailed to more than one address, separate address using commas, like "email1@site1.com, email2@site2.com"

$to_email = "joesmith@email.com";


And this, if it helps, is the process.php code from PHP Freebies:

<?php

//-----------------------------------------------------------------------------

/*         

        author: Thomaz Ebihara

        http://www.php-freebies.com     

        date: January 2006

        script version: 1.03

*/

//-----------------------------------------------------------------------------

?>

<?php

require_once("config.php");

require_once("functions.php");

?>

<?php

if($_POST['submit_check'] == 1)

    {

    // $ip = getAddress();

    $ip = getAddress();

    $php_version = phpversion();

    $body = "";

    $error_msg = "";



    $to = $to_email;



    if($_POST["$from_field"])

        {

        $from = $_POST[$from_field];

        }

    else

        {

        $from = $default_from_field;

        }

    

    if (eregi("\r", $from) || eregi("\n", $from))

        {

        die("Email headers manipulation detected");

        }

    

    if(!isValidEmail($from))

        {

        $error_msg .= "<li>Email Provided is not in valid form</li>";

        }



    if(!$_POST[$subject_field])

        {

        $subject = $default_subject;

        }

    else

        {

        $subject = $_POST[$subject_field];

        }        

    

    $body .= "*******************************************************************************";

    $body .= "\nUSER AGENT: " .$_SERVER['HTTP_USER_AGENT'];

    $body .= "\nFORM PAGE: " .$_SERVER['HTTP_REFERER'];

    $body .= "\nDATE: " .date("l dS of F Y h:i:s A");

    $body .= "\nUSER IP ADDRESS: " .$ip;

    $body .= "\n*******************************************************************************\n";

    

    foreach($_POST as $k => $v)

        {

        if(is_array($v))

            {

            foreach($v as $k2 => $v2)

                {

                $body .= "$k: $v2 on" . "\n";

                }

            }



        if($k != 'submit_check')

            {

            if(!is_array($v))

                {

                $body .= "$k: $v" . "\n";

                }

            }

        }

    foreach($required as $k => $v)

        {

        if(!array_key_exists($k, $_POST) || empty($_POST[$k]))

            {

            $error_msg .= "<li>$v</li>";

            }

        }

        

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

    $headers .= "MIME-Version: 1.0\r\n";

    $headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";

    $headers .= "X-Priority: $priority\r\n";

    $headers .= "X-Mailer: PHP $php_version\r\n";

    

    if(empty($error_msg))

        {

        if(mail($to, $subject, $body, $headers))

            {

            header("Location: $return_url");

            die();

            }

        else

            {

            die("email could not be sent");

            }

        }

    else

        {

        ?>

        <p>The following information is required:</p>

        <ul>

            <?php echo $error_msg; ?>

        </ul>

        <p>Please press your browser's back button and fill in the required fields.</p>

        <?php

        }

    }

?>


Given those two pieces of information, is it possible to add an additional "something" to the $to_email line so that it sends a copy of the submission to the user's email as well? I can happily provide more details or code, if it would help.

Thanks very much, I very much appreciate any help possible! :)
Link to comment
Share on other sites

The function eregi is deprecated as of PHP 5.3.0. This piece of code is not future proof. I'd advise you to find a newer script instead of trying to modify one that was originally released for PHP 4.3. The site phpfreebies was made back in 2005. That's nearly 8 years ago. Use at your own risk.

Edited by waynewex
Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

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