austin350s10 Posted December 14, 2009 Share Posted December 14, 2009 I have created a PHP mail script. I am having a problem though. In $body i am trying to put two values side by side like so $Fname $Lname. Where ever i use <br> tag the values appear in the final message but where i place the values side by side without a <br> tag then the values do not appear in the final message. I have already tried encasing the values in quotes and separating them with commas with no luck. I am certain this is an easy fix but i just don't know how. Any ideas.....please!!! Here is my code: <?php if (isset($_POST) && !empty($_POST['Fname'])){ session_start(); $_SESSION['Fname'] = $_POST['Fname']; } if (isset($_POST) && !empty($_POST['Lname'])){ session_start(); $_SESSION['Lname'] = $_POST['Lname']; } if (isset($_POST) && !empty($_POST['email'])){ session_start(); $_SESSION['email'] = $_POST['email']; } if (isset($_POST) && !empty($_POST['phone'])){ session_start(); $_SESSION['phone'] = $_POST['phone']; } if (isset($_POST) && !empty($_POST['attend'])){ session_start(); $_SESSION['attend'] = $_POST['attend']; } if (isset($_POST) && !empty($_POST['number'])){ session_start(); $_SESSION['number'] = $_POST['number']; } if (isset($_POST) && !empty($_POST['trans'])){ session_start(); $_SESSION['trans'] = $_POST['trans']; } ?> <?php /*subject and email variables*/ $emailSubject = 'Survivor or Care Provider Registration'; /*gathering data variables*/ $FnameField = $_POST['Fname']; $LnameField = $_POST['Lname']; $email = $_POST['email']; $phone = $_POST['phone']; $attendField = $_POST['attend']; $numberField = $_POST['number']; $transField = $_POST['trans']; $attend = implode(', ', $attendField); $trans = implode(', ', $transField); /*email field*/ $body = <<<EOD <br><hr><br> <h2>Registration Confirmation Email</h2> <hr> Name Registered: $Fname $Lname <br> Email Address: $email <br> Phone Number: $phone <br> Attending As: $attend <br> Bringing $number including $Fname $Lname <br> Will $Fname $Lname need transportation: $trans<br> <br> Thank you for registering!<br> EOD; /*email sender script*/ $sendto = $_POST['email']; $headers = "From: [email protected]\r\n"; $headers .= "Bcc: [email protected]\r\n"; $headers .= "Content-type: text/html\r\n"; $success = mail($sendto, $emailSubject, $body, $headers); /*resultes*/ $theResults = <<<EOD <html> <body> Thanks! </body> </html> EOD; echo "$theResults"; ?> Link to comment https://forums.phpfreaks.com/topic/185100-mail-script-problems/ Share on other sites More sharing options...
Deoctor Posted December 14, 2009 Share Posted December 14, 2009 delete all sessions and cookies from the browser and try echo for the session values and see whether they are there are not also check whether u have port 25 open or not.. Link to comment https://forums.phpfreaks.com/topic/185100-mail-script-problems/#findComment-977099 Share on other sites More sharing options...
mrMarcus Posted December 14, 2009 Share Posted December 14, 2009 for starters, i've never seen so many session_start()'s in one script. you only need to declare that one time per script (at your stage in the game, anyways), and before any output has been sent (headers()), or any cookies have been issued. just take session_start() out from each condition and place it once at the top of your script: <?php session_start(); if (isset($_POST) && !empty($_POST['Fname'])){ //...code... ?> and your code is very redundant in that you have the same condition in every statement: <?php if (isset($_POST) ... { instead, just do that once, encapsulating all other conditions: <?php if (isset($_POST)) { if (!empty ($_POST['Fname'])){ //stuff; } if (!empty ($_POST['Lname'])){ //stuff; } } ?> got it? just from looking at your code, i do not see any reason why having a line break (<br>) would stop your variables from being displayed in the email. doesn't make any sense. so, if you simply take out the <br> from this line, the vars disappear? <?php // ... code; $body = <<<EOD <br><hr><br> <h2>Registration Confirmation Email</h2> <hr> Name Registered: $Fname $Lname //<---took out the <br>, now variables won't show? Email Address: $email <br> Phone Number: $phone <br> Attending As: $attend <br> Bringing $number including $Fname $Lname <br> Will $Fname $Lname need transportation: $trans<br> <br> Thank you for registering!<br> EOD; ?> Link to comment https://forums.phpfreaks.com/topic/185100-mail-script-problems/#findComment-977100 Share on other sites More sharing options...
austin350s10 Posted December 14, 2009 Author Share Posted December 14, 2009 <?php // ... code; $body = <<<EOD <br><hr><br> <h2>Registration Confirmation Email</h2> <hr> Name Registered: $Fname $Lname <br>//<---this will not show do i need to separate the values somehow Email Address: $email <br> //<---this will show in the email Phone Number: $phone <br> Attending As: $attend <br> Bringing $number including $Fname $Lname <br> Will $Fname $Lname need transportation: $trans<br> <br> Thank you for registering!<br> EOD; ?> My email reads as follows: Registration Confirmation Email Name Registered: Email Address: [email protected] Attending As: survivor Bringing including Will need transportation: Thank you for registering! I an missing all the values that had two or more values on the same line of code. Hummm...... Link to comment https://forums.phpfreaks.com/topic/185100-mail-script-problems/#findComment-977111 Share on other sites More sharing options...
optikalefx Posted December 14, 2009 Share Posted December 14, 2009 print out $Fname $Lname and $trans. It looks like those aren't even set to anything. They are empty. If they aren't empty, try changing it one var in each line. If that works, try swapping out $Fname for a variable you know is working. Link to comment https://forums.phpfreaks.com/topic/185100-mail-script-problems/#findComment-977165 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.