[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

From to Email script

Posted on 2011-10-13
11
Medium Priority
?
204 Views
Last Modified: 2012-06-27

Hello Experts,

I wrote a code "form to email" in php.
It has tables, styles and php code (if statements).
after testing how it prints to the browser it looks good :-)
now i need to send it per email and i see couple of scripts

e.g.
$message =
$message .=

Open in new window

and so on.....

this means i have to work on that code i wrote like 2 hours to separate html from php .
i hope you understand what i mean?

is there an alternative way before i start this annoying process?
0
Comment
Question by:Refael
  • 7
  • 4
11 Comments
 
LVL 4

Expert Comment

by:CKY092
ID: 36965839
It sounds like you're trying to pass the email template to the php mail script. Is that accurate?
0
 

Author Comment

by:Refael
ID: 36965866

Hi CKY092

Not sure what you mean. Here is an sample of the code:

<html><body style="font-family:Arial, sans-serif; font-size:12px; color:#333;">
<table width="500" cellpadding="4" cellspacing="4" border="0" style="font-family:Arial, sans-serif; font-size:12px; color:#333; padding:0; margin:0;">
<tr><td valign="top" bgcolor="#B5B5B5" style="padding:10px;"><b>1). Personal and/or Business Information</b></td></tr>
<tr><td valign="top" bgcolor="#E1E1E1">
<table width="100%" cellpadding="4" cellspacing="4" border="0" style="font-family:Arial, sans-serif; font-size:12px; color:#333; padding:0; margin:0;">
<tr><td valign="top"><p><b>First Name:</b> <?php echo trim($FistName);?></p></td></tr>
<tr><td valign="top"><p><b>Last Name:</b> <?php echo trim($LastName);?></p></td></tr>
<tr><td valign="top">
<?php if (trim($CompanyName) != '') {?>
<p><b>Company Name:</b> <?php echo trim($CompanyName);?></p><?php }?>
</td></tr>.............................

Open in new window


This is only the first 8 lines.... It goes longer and has a lot of php statements.
When a user fill in the form that's the page that gets (post mode) all the variables from the form.
If you tell me there is no other way but separating the HTML and PHP and removing the opening and closing of the PHP tags along the script..... e.g.

$message = 'HTML';
PHP code............
$message.= 'HTML'
PHP code..............

then i will do that. I was hopping there is a better way :(
0
 
LVL 4

Expert Comment

by:CKY092
ID: 36965879
Well you can combine them in one line, like this:
$message .= '<tr><td valign="top"><p><b>First Name:</b>' . trim($FistName) . '</p></td></tr>';

Open in new window

But yes, you'll need to get your entire template into a PHP variable, like $message, in order to pass it to the mail function.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Expert Comment

by:CKY092
ID: 36965891
Here's a very simple example:
<?
$to = "joe@test.com";
$subject = "This is my suject";
$message = "<h1>State: " . $_POST['state'] . "</h1><br />";
$message .= "<p>Mountain: " . $_POST['location'] . "<br />";
$message .= "URL: " . $_POST['url'] . "</p>";
mail($to,$subject,$message);
?>

Open in new window

0
 

Author Comment

by:Refael
ID: 36965914


does it make sense? it looks like an error?

<tr><td valign='top'>". if (trim($CompanyName) != '') {."<p><b>Company Name:</b>". trim($CompanyName)."</p>.". }."

Open in new window

0
 
LVL 4

Expert Comment

by:CKY092
ID: 36965919
You can't have an if statement inside an append.
You'll need to move it outside the append statement, like:
if (trim($CompanyName) != ''){
    $message .= "<tr><td valign='top'>". trim($CompanyName) ."<p><b>Company Name:</b>". trim($CompanyName)."</p>";
}

Open in new window

0
 

Author Comment

by:Refael
ID: 36965945

ok so the only way is this long lasting way? there is no better way? i have around 190 lines with a lot of IF...
0
 
LVL 4

Accepted Solution

by:
CKY092 earned 2000 total points
ID: 36965950
The reason you need to do it this way, is you can only pass one $message variable to the mail function.

Sorry, wish I had a better answer for ya.
0
 
LVL 4

Expert Comment

by:CKY092
ID: 36966036
Did that answer your question?
0
 

Author Closing Comment

by:Refael
ID: 36966055
Thanks!
0
 
LVL 4

Expert Comment

by:CKY092
ID: 36966068
You're welcome!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses
Course of the Month20 days, 2 hours left to enroll

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question