/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] a php email question

Hello all,

I have a php script that processes a web form, sends and email and insert the information into a MySQL database. It all works fine, but I am trying to make some modifications to it and I’m not sure how to do it. I keep making changes and breaking it every time!

The first thing I am trying to do is change how the email is sent. When the email is sent to the recipient, the sender email address seems to be generated by the web server that the script is sitting on. I was hoping to change it to the email that the user entered with the form ($email). any ideas how this is done?

Heres what me code looks like:

[code=php]<?php

// read in variables from form

$to = $to;
$from = $from;
$email = $email;
$subject = “Registration”;
$address = $address;
$middlename = $middlename;
$lastname = $lastname;
$dateofbirth = $dateofbirth;
$town = $town;
$county = $county;
$country = $country;
$postcode = $postcode;
$telephone = $telephone;
$nickname = $nickname;
$password = $password;
$bigslickprivate = $bigslickprivate;
$bigslickplayers = $bigslickplayers;
$bigslickpreffered = $bigslickpreffered;
$today = date (“l, F jS Y”);

// database stuff

$dbhost = ‘host in here ‘;
$dbuser = ‘coolhan_admin’;
$dbpass = ‘wordword’;

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die (‘Error connecting to mysql’);

$dbname = ‘coolhan_bigslickreg’;
mysql_select_db($dbname);

$sql = “INSERT INTO players (dfirstname,dmiddlename,dlastname,demail, ddateofbirth, daddress, dtown, dcounty, dcountry, dpostcode, dtelephone, dnickname, dpassword, dprivateclub, dplayerclub, dpreferredclub) VALUES (‘$from’,’$middlename’,’$lastname’,’$email’,’$dateofbirth’,’$town’,’$county’,’$country’, ‘$postcode’,’$telephone’,’$nickname’,’$password’,’$bigslickprivate’,’$bigslickprivate’,’$bigslickplayers’,’$bigslickpreffered’)”;
$result = mysql_query($sql);

// check that required forms are complete

if (($to == “”) || ($from == “”) || ($email == “”) || ($subject == “”) || ($address == “”) || ($middlename == “”) || ($lastname == “”) || ($dateofbirth == “”) || ($town == “”) || ($county == “”) || ($country == “”) || ($postcode == “”) || ($telephone == “”) || ($nickname == “”) || ($password == “”) || ($bigslickprivate == “”) || ($bigslickplayers == “”) || ($bigslickpreffered == “”)) {
readfile(“blankfields.html”);
exit;
} else {
}

// check email format

if (($email != “”)) {
$locationofat = strpos($email, ‘@’);
$locationofdot = strrpos($email, ‘.’);
if (($locationofat == “0”) || ($locationofdot < $locationofat) || $locationofdot == “0”) {
readfile(“bademail.html”);
exit;
} else {
}
}

// create the email message

$msg .= “PLEASE FORWARD THIS EMAIL TO [email protected] nnn”;

if ($from != “”) {
$msg .= “First Name : $fromn”;
}
if ($middlename != “”) {
$msg .= “Middle Name : $middlenamen”;
}
if ($lastname != “”) {
$msg .= “Last Name : $lastnamen”;
}
if ($email != “”) {
$msg .= “Email : $emailn”;
}
if ($dateofbirth != “”) {
$msg .= “Date of Birth : $dateofbirthn”;
}
$msg .= “Address : $addressn”;

if ($town != “”) {
$msg .= “Town : $townn”;
}
if ($county != “”) {
$msg .= “County : $countyn”;
}
if ($country != “”) {
$msg .= “Country : $countryn”;
}
if ($postcode != “”) {
$msg .= “Postcode : $postcoden”;
}
if ($telephone != “”) {
$msg .= “Telephone : $telephonen”;
}
if ($nickname != “”) {
$msg .= “Nick Name : $nicknamen”;
}
if ($password != “”) {
$msg .= “Password : $passwordn”;
}
if ($bigslickprivate != “”) {
$msg .= “Join the Big Slick Private Members club? : $bigslickprivaten”;
}
if ($bigslickplayers != “”) {
$msg .= “Join the Big Slick Players Club? : $bigslickplayersn”;
}
if ($bigslickpreffered != “”) {
$msg .= “Obtain membership to Big Slick’s preferred members club? : $bigslickprefferednn”;
}
$msg .= “Sent : $todayn”;

// send the email

$mailheaders = “BigSlick Site registration ( $from )<> n”;
$mailheaders .= “Reply-To: $emailnn”;

mail($to, $subject, $msg, $mailheaders);

// pull in the thank you file

readfile(“thankyou.html”);

exit;

?>[/code]

Thanks guys,

John

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@chazzyApr 25.2006 — add this to your headers:

[code=php]
$mailheaders .= "From: $fromnn";
[/code]
Copy linkTweet thisAlerts:
@fogofogoauthorApr 25.2006 — add this to your headers:

[code=php]
$mailheaders .= "From: $fromnn";
[/code]
[/QUOTE]


Thanks!
×

Success!

Help @fogofogo 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 5.18,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...