473,396 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Email headers $message - Don't Show if not exists

3
Somewhat new to Php. I inherited a simple piece of email processing code that stores the submitted form fields in the $message variable. Their are some fields that may not exist when the form is submitted so I'd like to not include them.

The second row (AddName2) is an example of a row I don't want to include in the email submission if it doesn't exist:
Expand|Select|Wrap|Line Numbers
  1. $message = "Date: " . date("F d, Y") . " $n
  2. <table>
  3. <tr><th $headerStyle >Name</th><td>" . $this->AddName1 . "</td></tr>
  4. <tr><th $headerStyle >Name</th><td>" . $this->AddName2 . "</td></tr>
  5. <table>
  6. ";
I tested unsuccessfully like this:
Expand|Select|Wrap|Line Numbers
  1. if (isset($_POST["AddName2"])) {                 
  2. <tr><th $headerStyle >Name</th><td>" . $this->AddName2 . "</td></tr>
  3. " . } . "
  4.  
Thanks in advance.
Jan 10 '12 #1
7 1773
dburns

use this code
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. if($_POST["AddName2"] != '')
  3. {
  4. echo "<tr><td". $headerStyle." >Name</td><td>" . $_POST["AddName2"] . "</td>
  5. </tr>";
  6. }
  7. ?>
  8.  
Jan 10 '12 #2
dburns
3
Thank you but it appears the code enveloped in the $message variable is strictly defining what's allowed between the two dots:
Expand|Select|Wrap|Line Numbers
  1. " . if($_POST["AddName2"] != '') { 
  2. echo "<tr><td". $headerStyle." >Name</td><td>" . $_POST["AddName2"] . "</td></tr>" ; 
  3. } . "
  4.  
Per above, I still get syntax error: syntax error, unexpected T_IF
Jan 10 '12 #3
Dormilich
8,658 Expert Mod 8TB
Per above, I still get syntax error: syntax error, unexpected T_IF
of course. an if statement is not a string (which you would need when using the concatenation operator).
Jan 10 '12 #4
dburns

i can't make out what you say. Could u send the entire code including your PHP tags.
Also why do you add dot before if condition

" . if($_POST["AddName2"] != '') {
Jan 11 '12 #5
dburns
3
Thank you again for your followup. Here's the code, which contains "Name & Email" rows I would like to 'not include' if they're not filled out.

Expand|Select|Wrap|Line Numbers
  1.     public function sendAdminNotification($email, $subject) {
  2.  
  3.         $n = "<br />";
  4.  
  5.         $headerStyle = 'style="font-weight: bold; background-color: #BCDAFC;"';
  6.         $message = "Date: " . date("F d, Y") . " $n
  7.         $n
  8.         $n Non Profit Org Registration Submitted. Information below.:
  9.         $n
  10.         <table cellpadding='3' colspacing='0'>
  11.             <tr><th $headerStyle >First Name</th><td>" . $this->first_name . "</td></tr>
  12.             <tr><th $headerStyle >Middle Initial</th><td>" . $this->middle_initial . "</td></tr>
  13.             <tr><th $headerStyle >Last Name</th><td>" . $this->last_name . "</td></tr>
  14.             <tr><th $headerStyle >Address</th><td>" . $this->address . "</td></tr>
  15.             <tr><th $headerStyle >Address 2</th><td>" . $this->address2 . "</td></tr>
  16.             <tr><th $headerStyle >City</th><td>" . $this->city . "</td></tr>
  17.             <tr><th $headerStyle >State</th><td>" . $this->state . "</td></tr>
  18.             <tr><th $headerStyle >Zip Code</th><td>" . $this->zip . "</td></tr>
  19.             <tr><th $headerStyle >Telephone</th><td>" . $this->telephone . "</td></tr>
  20.             <tr><th $headerStyle >Fax</th><td>" . $this->fax . "</td></tr>
  21.             <tr><th $headerStyle >Email</th><td>" . $this->email . "</td></tr>
  22.             <tr><th $headerStyle ># Participating</th><td>" . $this->num_individuals . "</td></tr>        
  23.             <tr><th $headerStyle >Name & Email #1</th><td>" . $this->AddName1 . "</td><td>" . $this->AddEmail1 . "</td></tr>
  24.             <tr><th $headerStyle >Name & Email #2</th><td>" . $this->AddName2 . "</td><td>" . $this->AddEmail2 . "</td></tr>            
  25.             <tr><th $headerStyle >Name & Email #3</th><td>" . $this->AddName3 . "</td><td>" . $this->AddEmail3 . "</td></tr>            
  26.             <tr><th $headerStyle >Name & Email #4</th><td>" . $this->AddName4 . "</td><td>" . $this->AddEmail4 . "</td></tr>            
  27.             <tr><th $headerStyle >Name & Email #5</th><td>" . $this->AddName5 . "</td><td>" . $this->AddEmail5 . "</td></tr>            
  28.         </table>
  29.         ";
  30.  
  31.         $this->_headers[] = 'From: Non Profit Contact'  . ' <noreply@NPO_test.org>';
  32.         //$this->_headers[] = 'NPO 1 Registration (mailto:noreply@NPO_test.org)';
  33.  
  34.  
  35.  
  36.         mail($email, $subject, $message, implode("\r\n", $this->_headers)) or die("Could not send admin email.");
  37.     }
  38.  
Jan 11 '12 #6
Dormilich
8,658 Expert Mod 8TB
you would need to test the property for a null value and only then add the row to the table.
Jan 11 '12 #7
hi dburns

please try out the below code. u were missing some quote marks in between.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. public function sendAdminNotification($email, $subject) 
  3.                 {
  4.  
  5.         $n = "<br />";
  6.  
  7.         $headerStyle = 'style="font-weight: bold; background-color: #BCDAFC;"';
  8.         $message = "Date: " . date("F d, Y") . $n;
  9.         $message .= $n." Non Profit Org Registration Submitted. Information below.:";
  10.         $message .= $n;
  11.  
  12.         $message .= "<table cellpadding='3' colspacing='0'>
  13.             <tr><th ".$headerStyle." >First Name</th><td>" . $this->first_name . "</td></tr>
  14.             <tr><th ".$headerStyle." >Middle Initial</th><td>" . $this->middle_initial . "</td></tr>
  15.             <tr><th ".$headerStyle." >Last Name</th><td>" . $this->last_name . "</td></tr>
  16.             <tr><th ".$headerStyle." >Address</th><td>" . $this->address . "</td></tr>
  17.             <tr><th ".$headerStyle." >Address 2</th><td>" . $this->address2 . "</td></tr>
  18.             <tr><th ".$headerStyle." >City</th><td>" . $this->city . "</td></tr>
  19.             <tr><th ".$headerStyle." >State</th><td>" . $this->state . "</td></tr>
  20.             <tr><th ".$headerStyle." >Zip Code</th><td>" . $this->zip . "</td></tr>
  21.             <tr><th ".$headerStyle." >Telephone</th><td>" . $this->telephone . "</td></tr>
  22.             <tr><th ".$headerStyle." >Fax</th><td>" . $this->fax . "</td></tr>
  23.             <tr><th ".$headerStyle." >Email</th><td>" . $this->email . "</td></tr>
  24.             <tr><th ".$headerStyle." ># Participating</th><td>" . $this->num_individuals . "</td></tr> ";
  25.             if($this->AddName1 != '')
  26.             {
  27.                 $message .="<tr><th ".$headerStyle." >Name & Email #1</th><td>" . $this->AddName1 . "</td><td>" . $this->AddEmail1 . "</td></tr>";
  28.             }
  29.            if($this->AddName1 != '')
  30.             {
  31.                 $message .="<tr><th ".$headerStyle." >Name & Email #2</th><td>" . $this->AddName2 . "</td><td>" . $this->AddEmail2 . "</td></tr>";
  32.             }
  33.             if($this->AddName1 != '')
  34.             {
  35.                 $message .="<tr><th ".$headerStyle." >Name & Email #3</th><td>" . $this->AddName3 . "</td><td>" . $this->AddEmail3 . "</td></tr>";  
  36.             }
  37.             if($this->AddName1 != '')
  38.             {
  39.                 $message .="<tr><th ".$headerStyle." >Name & Email #4</th><td>" . $this->AddName4 . "</td><td>" . $this->AddEmail4 . "</td></tr>"; 
  40.             }
  41.             if($this->AddName1 != '')
  42.             {
  43.                 $message .="<tr><th ".$headerStyle." >Name & Email #5</th><td>" . $this->AddName5 . "</td><td>" . $this->AddEmail5 . "</td></tr>";
  44.             }
  45.  
  46.         $message .="</table> ";
  47.  
  48.         $this->_headers[] = 'From: Non Profit Contact'  . ' <noreply@NPO_test.org>';
  49.         //$this->_headers[] = 'NPO 1 Registration (mailto:noreply@NPO_test.org)';
  50.  
  51.  
  52.  
  53.         mail($email, $subject, $message, implode("\r\n", $this->_headers)) or die("Could not send admin email.");
  54.    }
  55.  ?>
  56.  
Jan 12 '12 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: dont bother | last post by:
Hi, I am a new bie experimenting with python. I have this piece of code to parse the received headers from emails. However, when I run with a file as an argument it skips lines like: 1, 3, 5...
0
by: Jerry | last post by:
After a view Times of Compiling I get the Message "Class alread exists" The code Stops on diverent Places, so there is no specific line where the Error exists. If I the restart the IIS every...
0
by: Josip Habjan | last post by:
Hi, I have VS 2003 installed. In VS 2002 all worked fine, but... when I reinstall my PC and put VS 2003, ASP.NET dont work propertly.. All other controls are fine, only DataGrid dont exist......
2
by: soundar rajan | last post by:
Hi, I wanna display messagebox, and also at the bottom i wanna display "Dont show again" with checkbox using VB.NET. Immediate help needed!!!!
2
by: Glenn | last post by:
hello: I am working through "Beginning PHP5 Web Development", by WROX, and I am having trouble sending HTML email messages in one application. The email goes through, but is displayed only as...
0
by: James | last post by:
I'm sending outgoing email with headers that I've added to identify them. If they bounce back, they end up in a centralized mailbox. What I'm trying to do at this point is read the header of the...
4
by: Christoph Haas | last post by:
Hello, everyone... I'm trying to send an email to people with non-ASCII characters in their names. A recpient's address may look like: "Jörg Nørgens" <joerg@nowhere> My example code: ...
3
by: Rick | last post by:
I'm adding columns to a datagridview in code. When I run the program the data is bound correctly, but none of the column headers show. Can someone point out what obvious mistake I am making? ...
3
by: Jeff | last post by:
I have been searching google for a way to read the email headers for mail on a pop server but cannot find any source samples. Are there any sample that anyone know about and if so can they post...
3
by: dearprasan | last post by:
I am trying to show a message box with additional feature to put a checkbox for something like "Dont show me again" etc. Is there an easy way to achieve this?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.