Reply-to / From

I have this code in several forms, but when I recieve messages from any of them the from/reply address is either blank or some long name that is unrecognizable.

This is the code i use:


$from = '$email';

$headers = "Content-type: text/html\\r\
";
$headers .= "From: $email\\r\
";
$headers .= "Reply-To: $email\\r\
";
$headers .= "Return-Path: $email\\r\
";

Well clearly you’re not doing something right in your code before it. Also your very first line has $from = ‘$email’; which will not work because the single quotes tell php not to do anything and so $from will literally be ‘$email’ not the value of $email.

You need to show us the rest of the code.

Here is the full code:

<?php
session_start();

require_once('recaptchalib.php');
        $errors = array('recaptcha'=>'');
        //reCaptcha public & private keys
        $publickey  = "6LfWgL8SAAAAALli4JmS3bijs_gF7F9JufTg0CVJ";
        $privatekey = "GFVWgL8SAAAAAGFevGi3vp-p4lvYyeQ2ToWR8ryf";
/* Subject and Email Variables */
        $from = '$email';
        $subject = 'Certificate Request';
        $to = 'samuel@searchtransparencysem.com';
        //samuel@searchtransparencysem.com
        //aaa@aaa.com

/* Gathering Data Variables */
if(isset($_POST['quote_form'])){
        $flag = true;
        $resp = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST['recaptcha_challenge_field'], $_POST['recaptcha_response_field']);
                if (!$resp->is_valid) {
                        $errors['recaptcha'] = $resp->error;
                        $flag = false;
                }
        // Does everything the greyed out part does. Also sets cookies for elements.
        foreach($_POST as $key=>$value){
                if(is_array($_POST[$key])){
                        if($key = "insurance_lines"){
                                foreach($value as $index=>$name){
                                        $$name = $name;
                                        setcookie($name, $$name);
                                }
                                $$key = implode(", ", $value);
                        }else{
                                setcookie($key, $$key);
                                $$key = implode(", ", $value);
                        }
                }else{
                        if($key == "recaptcha_challenge_field" || $key == "recaptcha_response_field"){ continue;}
                        $$key = $value;
                        //echo "<strong>".$key."</strong> ".$$key."<br />";
                        setcookie($key, $$key);
                }
        }
   if($flag == true) {
                $body =<<<BODY
                     <br><hr><br>
						<h2>Request a Certificate</h2>
						Name of Insured: $name_of_insured <br>
						Name of Person Requesting the Certificate: $person_requesting_certificate <br>
						Telephone: $telephone <br>
						Email Address: $email_address <br>
						Fax: $fax <br>
						Name of Certificate Holder: $name_of_certificate_holder <br>
						Mailing Address: $mailing_address <br>
						Mailing City: $mailing_city <br>
						Mailing State: $mailing_state <br>
						Mailing Zip: $mailing_zip <br>
						Requiring to be named as an additional insured: $additional_insured <br>
						Relationship of Certificate Holder to the Insured: $relationship <br>
						Lines of Business to be included: $insurance_lines <br>
						Please note anything you would like us to know while quoting your account: $things_to_know <br>
						How did you hear about us?: $referral_source <br>
						Explain Other or give the name of the person that referred you: $referral_source_explain <br>
BODY;
				$headers = "Content-type: text/html\\r\
";
				$headers .= "From: $email\\r\
";
				$headers .= "Reply-To: $email\\r\
";
				$headers .= "Return-Path: $email\\r\
";
                $send = mail($to,$subject,$body,$headers);
                header('Location: sent.html');
                exit;
        }
}
?>

Youre code still doesnt show how $email is being set.

You’ll need to find the part of the code where its being set and start looking there for errors.

Right, WHERE are you setting $email? - I don’t see anything like $email = $_POST[‘email’]; anywhere.

Secondly as I’ve mentioned above, $from = ‘$email’ will only set $from to ‘$email’. By that I mean if you


print $from;

your html will literally display $email NOT the value of it.

Please don’t dump and run. I’ve made the point above in my last post you need to fix it before just dumping your code on us to fix and then running before even fixing this basic fault.

Sorry about the “dump and run”. I’ve been overloaded with other projects recently and am just getting back to this one now. I have fixed this problem on my own. I appreciate everyone’s input.

Thanks,

Sam

Care to share the solution with us? It might be useful to others having a similar problem. :slight_smile:

Below is my code I use to send out email:


		$myemail = "myemail@gmail.com";
		$subj = "Contact Form message!";
		$emess = "Name: ".$fv['name']."\\r\
";
		$emess .= "Email: ".$fv['email']."\\r\
";
		$emess .= "Message: \\r\
".$fv['msg']."\\r\
";

		$eheader = "From: ".$fv['email']."\\r\
";

		$mailsend=mail("$myemail","$subj","$emess","$eheader");

It will put the visitor’s email into “From” field in the email, so you can just hit reply to reply to that visitor…

<snip/>

SOLUTION:

As it usually is, my problem was simply the overlook of a small detail. I had written “$email_address” as “$email” instead.

This is what I had:

$from = ‘$email’;

$headers = "Content-type: text/html\r
";
$headers .= "From: $email\r
";
$headers .= "Reply-To: $email\r
";
$headers .= "Return-Path: $email\r
";

This is what I now have:

$from = ‘$email_address’;

$headers = "Content-type: text/html\r
";
$headers .= "From: $email_address\r
";
$headers .= "Reply-To: $email_address\r
";
$headers .= "Return-Path: $email_address\r
";

Thanks again to everyone in this thread for your help!