Menu

'From' Email Address

Help
Julian
2010-11-18
2013-06-03
  • Julian

    Julian - 2010-11-18

    I have seen this topic discuss in great detail on the forum however I am still unable to get my form to show the email address of the sender in the 'from' heading.  It currently shows server details.

    I need this so that I can use the 'reply' button to reply directly to people who submit the form to my site.

    The code that I have is as follows:

    <?php

    $where_form_is="http://".$_SERVER.strrev(strstr(strrev($_SERVER),"/"));

    session_start();
    if( ($_SESSION==$_POST) && (!empty($_POST)) ) {

    mail("??????????@????????.co.uk","Enrollment Form","ENROLLMENT DETAILS:

    Full Name: " . $_POST . "

    Address (Including Postcode): " . $_POST . "

    Mobile Number: " . $_POST . "

    Your Email Address: " . $_POST . "

    How did you hear about the MADE Academy?: " . $_POST . "

    Childs Full Name: " . $_POST . "

    Childs Date of Birth: " . $_POST . "

    Preferred Start Date: " . $_POST . "

    Experience: " . $_POST . "

    Would you like to be considered for the agency?: " . $_POST . "

    Do you give permission for your childs photograph to be taken in class and used?: " . $_POST . "

    ","from: enrol@madeacademy.co.uk" );

    include("confirm.html");

    }
    else {
    echo "Invalid Captcha String.";
    }

    ?>

    If anyone can give me some very simple step by step instructions on how I can achieve this I would be most gratefull.

    Regards

     
  • TNTEverett

    TNTEverett - 2010-11-19

    I've never seen it done this way and I don't think you can modify the header successfully with only partial information.  The best source for learnig how this can be accomplished is here:
    http://php.net/manual/en/function.mail.php

     
  • Julian

    Julian - 2010-11-19

    Thank you for the reply.

    I have another scirpt that I use and on this script I get what I want (the 'from' heading showing the senders email address).

    I have tried to follow the instrcutions as per the link that you have provided and I still cant get it to work.

    Here is the script where it does work:

    <?php
    function died($error)
    {
        // your error code can go here
        echo "We are very sorry, but there were error(s) found with the information you submitted. ";
        echo "These errors are as follows:<br /><br />";
        echo $error."<br /><br />";
        echo "Please click on the back button and fix these errors.<br /><br />";
        die();
    }
    function clean_string($string)
    {
      $bad = array("content-type","bcc:","to:","cc:","href");
      return str_replace($bad,"",$string);
    }
    if(isset($_POST['email']))
    {
        // EDIT THE 2 LINES BELOW AS REQUIRED
        $email_to = "******@*******.co.uk";
        $email_subject = "Enquiry";
        // validation expected data exists
        if(!isset($_POST['name']) || !isset($_POST['email']) ||  !isset($_POST['Inquiry']))
        {
            died('We are sorry, but there appears to be a problem with the information you submitted.');
        }
        $name = $_POST['name']; // required
        $email_from = $_POST['email']; // required
        $Inquiry = $_POST['Inquiry']; // required
        $error_message = "";
        $email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$";
        $string_exp = "^[a-z .'-]+$";
        if(!eregi($string_exp,$name)) {
            $error_message .= 'The Name you entered does not appear to be valid.<br />';
        }
        if(!eregi($email_exp,$email_from)) {
            $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
        }
        if(strlen($Inquiry) < 10) {
            $error_message .= 'The Enquiry you entered does not appear to be valid.<br />';
        }
        if(strlen($error_message) > 0) {
            died($error_message);
        }
        $email_message = "\n\n";
        $email_message .= "Name: ".clean_string($name)."\n";
        $email_message .= "Email: ".clean_string($email_from)."\n";
        $email_message .= "Enquiry: ".clean_string($Inquiry)."\n";
        // create email headers
        $headers = 'From: '.$email_from."\r\n".'Reply-To: '.$email_from."\r\n".'X-Mailer: PHP/' . phpversion();
        @mail($email_to, $email_subject, $email_message, $headers);
    ?>
    

    Regards

     
  • TNTEverett

    TNTEverett - 2010-11-20

    Turns out I have used this method before.  Here is an old example in a form that is still working.

    "mail("mypersonalemail@comcast.net","Form Submitted by $FirstName $LastName",$message,"From: $Email");"

    Try capitolizing the "From:" and substitute the raw email address with a variable.

    $Email=$_POST;

    then

    ","From: $Email" );

     
  • Julian

    Julian - 2010-11-20

    Thanks for the reply.

    I have sorted this now by replacing:

    ","from: enrol@madeacademy.co.uk" );
    include("confirm.html");
    

    with

    ","from:   $_POST[field_4]" );
    include("confirm.html");
    

    with

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.