Jump to content

Mail Script Problems


austin350s10

Recommended Posts

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: auto-confirm@xxxxxxxxxxxx.com\r\n";
$headers .= "Bcc: webmaster@xxxxxxxxxxxx.com\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
Share on other sites

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
Share on other sites

<?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: xxxx@yahoo.com

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.