Copy link to clipboard
Copied
How do I add session variables to the Subject field and the Message body of the email? Tried many combinations, but do not seem to get the syntax right.
This is the code I have. I need to change all those form variables in $msg into session variables. The $to part is taken care of. What remains are the $subject field and the $msg field.
$to='To: ' . $_SESSION['toemail'];
$subject="$firstname $lastname, Your Registration Details";
$from="From: mail@xyz.com";
$msg="Dear $title $firstname $lastname\r\n\nThank you for registering for the design of your Dream Home.\r\nWe have received the following details from you-\r\n\nClient Details-\r\n\nOccupation: $occupation \r\nPhone No: $phone \r\nE-mail: $email\r\n\nPresent Location:\r\n$location\r\n\nPresent Address:\r\n$address\r\n\n\nFollowing are the Design Requirements specified by you-\r\n\nBasic Features\r\n\nNo. of Floors: $floors\r\nNo. of Bedrooms: $bedrooms\r\nNo. of Bathrooms: $bathrooms\r\nFloor Area: $sqft\r\n\nFurther Suggestions: $further\r\n\n\nType of Floor Plan\r\n\nSplit Floor: $splitfloor\r\n- Remarks: $splitfloorremarks\r\nOpen Floor: $openfloor\r\n- Remarks: $openfloorremarks\r\n\n\nList of Rooms to be Included\r\n\nFoyer: $foyer\r\n- Remarks: $foyerremarks\r\nDrawing: $drawing\r\n- Remarks: $drawingremarks\r\nFormal Living: $formalliving\r\n- Remarks: $formallivingremarks\r\nFamily Living: $familyliving\r\n- Remarks: $familylivingremarks\r\nHome Office: $homeoffice\r\n- Remarks: $homeofficeremarks\r\nDining: $dining\r\n- Remarks: $diningremarks\r\nMaster Bedroom: $master\r\n- Remarks: $masterremarks\r\nMaster Bathroom: $masterbath\r\n- Remarks: $masterbathremarks\r\nMaster Dressing: $masterdress\r\n- Remarks: $masterdressremarks\r\nBedroom: $bed\r\n- Remarks: $bedremarks\r\nBathroom: $bath\r\n- Remarks: $bathremarks\r\nDress: $dress\r\n- Remarks: $dressremarks\r\nStudy: $study\r\n- Remarks: $studyremarks\r\nLibrary: $library\r\n- Remarks: $libraryremarks\r\nPowder Room: $powder\r\n- Remarks: $powderremarks\r\nPrayer Room: $prayer\r\n- Remarks: $prayerremarks\r\nKitchen: $kitchen\r\n- Remarks: $kitchenremarks\r\nPantry: $pantry\r\n- Remarks: $pantryremarks\r\nUtility/Work Area: $utility\r\n- Remarks: $utilityremarks\r\nBalcony: $balcony\r\n- Remarks: $balconyremarks\r\nStore: $store\r\n- Remarks: $storeremarks\r\nLaundry: $laundry\r\n- Remarks: $laundryremarks\r\nVeranda: $veranda\r\n- Remarks: $verandaremarks\r\nCar Porch: $carporch\r\n- Remarks: $carporchremarks\r\nGarage: $garage\r\n- Remarks: $garageremarks\r\nHome Theater: $theater\r\n- Remarks: $theaterremarks\r\nMaid's Room: $maid\r\n- Remarks: $maidremarks\r\n\nOther General Remarks: $general\r\n\nPlease note that the fields that were left blank in your form will be considered as undecided details and used in the Architect's discretion.\r\nIf you wish to add any more Design requirements later, please feel free to reply to this email with details.";
$fla=mail($to,$subject,$msg,$from);
Thanks in advance!
askintrades wrote:
How do I add session variables to the Subject field and the Message body of the email?
What exactly is it that you want to do? Given the nature of your question, it seems as though you probably don't know what a session variable is used for. The PHP Manual describes the purpose of sessions here: http://docs.php.net/manual/en/intro.session.php.
...
I need to change all those form variables in $msg into session variables. The $to part is taken care of. What remains are the $subject fie
Copy link to clipboard
Copied
askintrades wrote:
How do I add session variables to the Subject field and the Message body of the email?
What exactly is it that you want to do? Given the nature of your question, it seems as though you probably don't know what a session variable is used for. The PHP Manual describes the purpose of sessions here: http://docs.php.net/manual/en/intro.session.php.
I need to change all those form variables in $msg into session variables. The $to part is taken care of. What remains are the $subject field and the $msg field. $to='To: ' . $_SESSION['toemail'];
Why do you need to change the form variables into session variables? Are they already stored in session variables, or are they coming directly from the form?
The $to part is not taken care of. When you pass $to to the mail() function, it should contain only an email address, not a string that begins with 'To: '.
Copy link to clipboard
Copied
Thank you David for the response. As you guessed, I'm fairly new with session variables. What I'm looking for is as follows-
On my Architecture website, I have an html form where clients would enter their design preferences and Submit. The website then sends an email to the client with the details they had entered; for confirmation. This had worked properly with form variables as the email is sent right after the form is filled.
However, now I have added a License agreement page and a second form with other design details, which has to be filled in before the client's email is sent. So, I've set the Page1 form variables as session variables to carry over to the 4th page where it is sent as email. I am able to retrieve the session variables on the fourth page, but what I require is the correct syntax for using it in the subject field and the message body of the email, so that the clients get them in their email.
I had earlier used the following php code for sending emails using form variables-
$to="From: $email";
$subject="$name, Thank you for visiting our website.";
$from="mail@xyz.com";
$msg="Your Reg. details-\r\n\n$name\r\n$address\r\n\nPhone No: $phone \r\nE mail: $email \r\n\nMessage:\n$message";
$fla=mail($to,$subject,$msg,$from);
; where the form variables are- $name, $address, $phone, $email, $message
I have now set them as session variables-
<?php
session_start();
$_SESSION['name'] = $name;
$_SESSION['address'] = $address;
$_SESSION['phone'] = $phone;
$_SESSION['email'] = $email;
$_SESSION['message'] = $message;
?>
; and I'm being able to retrieve them on the 4th subsequent page. As mentioned, what I am looking for is the correct syntax to use this data in a php email code.
I will be very grateful if you could provide me with a sample php email code for sending an email with session variables in the 'from', 'to', 'subject' and 'message' fields.
Copy link to clipboard
Copied
Hi David, did a lot of tweaking and finally got it to work. Thanks for the reference link!
This is how the code looks now-
$to='To: ' . $_SESSION['email'];
$title=$_SESSION['title'];
$firstname=$_SESSION['firstname'];
$lastname=$_SESSION['lastname'];
$subject="Hello! $firstname $lastname";
$from="From: mail@xyz.com";
$msg="Dear $title $firstname $lastname\r\nThank you for Registering on our website."
$fla=mail($to,$subject,$msg,$from);
I guess I committed the newbie mistake of not assigning the $ values before using them in the message.:)
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more