/    Sign up×
Community /Pin to ProfileBookmark

PHP Email Form Question

Hi, a friend of mine asked me to make him a contact form. He uses Yahoo Small Business as his hosting. For some reason you have to have [I]your[/I] email as the from address, otherwise the email won’t send..

Is there a way that even though the from address is set already, when he clicks reply from the email he received, it will reply to the address that was entered in the form?

Thanks.

to post a comment
PHP

8 Comments(s)

Copy linkTweet thisAlerts:
@SheldonAug 19.2008 — set reply/return paths

[code=php]

$headers = "From: your name <[email protected]>n";
$headers .= "Reply-To: their name <[email protected]>n";
$headers .= "Return-Path: their name <[email protected]>n";

mail("[email protected]", "Mail Subject", "Mail Message", $headers);
[/code]
Copy linkTweet thisAlerts:
@theflyingminstauthorAug 19.2008 — Hey thanks for replying Sheldon. I tried your code, but I think Yahoo must be blocking it or something because when I hit respond it still has the From email address as the reply-to..
Copy linkTweet thisAlerts:
@NogDogAug 19.2008 — You may need to "rn" instead of just "n" as the header separator.
Copy linkTweet thisAlerts:
@theflyingminstauthorAug 19.2008 — Thanks for the tip NogDog, I just tried it and got the same results though..
Copy linkTweet thisAlerts:
@NogDogAug 19.2008 — The Reply-To: should work, though. Perhaps we need to see the applicable part of your code?
Copy linkTweet thisAlerts:
@theflyingminstauthorAug 19.2008 — K, thanks. This is what I have since the last post:

<?php


// get posted data into local variables

$EmailFrom = "[email protected]";

$EmailTo = "[email protected]";

$Subject = "Inquiry at Gdanski.com";

$Name = Trim(stripslashes($_POST['Name']));

$Email = Trim(stripslashes($_
POST['Email']));

$Phone = Trim(stripslashes($_POST['Phone']));

$Inquiry = Trim(stripslashes($_
POST['Inquiry']));

// validation

$validationOK=true;

if (!$validationOK) {

print "<meta http-equiv="refresh" content="0;URL=error.htm">";

exit;

}

$headers = "From: your name <[email protected]>rn";

$headers .= "Reply-To: their name <[email protected]>rn";

$headers .= "Return-Path: their name <[email protected]>rn";

// prepare email body text

$Body = "";

$Body .= "Name: ";

$Body .= $Name;

$Body .= "n";

$Body .= "Email: ";

$Body .= $Email;

$Body .= "n";

$Body .= "Phone: ";

$Body .= $Phone;

$Body .= "n";

$Body .= "Inquiry: ";

$Body .= $Inquiry;

$Body .= "n";

// send email

$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>", $headers);

// redirect to success page

if ($success){

print "<meta http-equiv="refresh" content="0;URL=post-contact.htm">";

}

else{

print "<meta http-equiv="refresh" content="0;URL=post-contact-not-send.htm">";

}

?>
Copy linkTweet thisAlerts:
@NogDogAug 19.2008 — The add.'l headers are the 4th parameter of the mail() command, but you had them as the 5th. Try this:
[code=php]
$success = mail($EmailTo, $Subject, $Body, $headers);
[/code]
Copy linkTweet thisAlerts:
@theflyingminstauthorAug 19.2008 — Hey, wow it worked. Thanks so much!!
×

Success!

Help @theflyingminst spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...