Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Tectite form, trying to email HTML form as HTM attachment

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Tectite form, trying to email HTML form as HTM attachment

Postby projectile » Tue Mar 19, 2013 1:28 pm

Hello
I have no PHP experience and spent the day trying to research this issue.

I've created a form using Tectite Contact Form Processing tool, formmail.

When the form is completed by a user, an email is sent to the hard coded recipient. The completed form is emailed into the body of email, using a HTML template.

Now , I need to somehow grab this completed HTML form, and send as a HTM attachment to another email address, with specific subject matter.

the form passes completed forms fields to formmail.php.

here is formmail.php which is huge, and I have tried to follow the code, but cannot get my head around all the functions.


If I insert the below code into the top of Formmail.php , it will generate an email with the HTML template, however the template doesn't contain the completed fields from the form.

Is there anyway I can modify the formmail.php to store the completed HTMLtemplate to a temp folder , so the below code can grab the HTM file , and send as an attachment. or is there another way I can do this?

Code: Select all
require('Mail.php');
require('mime.php');
// define recipient
$recipient = 'email@domain.com';
// define local path to excel file
$htmFilename = 'c:/Inetpub/wwwroot/forms/techtite/fmtemplates/OSpayment_template.htm';
// define mail headers
$headers = array('From'       => 'Admin <email@domain.com>',
                               'To'         => $recipient,
                               'Subject'    => 'OSpayment_template.htm'
                              );   
    $mime = new Mail_mime("\n");
    $mime->setTXTBody('This is the "TXT" part of the message');
    // if client reading this email, reads HTML (multi-part) messages,
    // he'll see this HTML body message
$mime->setHTMLBody('</pre>
<h1>This is the HTML part of the message</h1>
<pre></pre>
<p style="background-color: beige;">test</p>
<pre>');

    $mime->addAttachment($htmFilename,
 'text/html',
"OSpayment_template.htm");
    // get body of the e-mail message from Mail_mime class.
    $body = $mime->get();
    // get headers
    $hdrs = $mime->headers($headers);
    // now, lets send e-mail using the PEAR Mail class.
    $mail = Mail::factory('mail');
    $mail->send($recipient, $hdrs, $body);



formmail.php can be viewed here (http://www.tectite.com/formmail.zip), as it is too big to put into this post.

I have tried posting this question tectite forum, but that forum appears to be inactive.

Any help would be greatly appreciated / thanks
projectile
New php-forum User
New php-forum User
 
Posts: 3
Joined: Tue Mar 19, 2013 12:38 pm

Re: Tectite form, trying to email HTML form as HTM attachmen

Postby johnj » Wed Mar 20, 2013 1:31 am

In $mail->send,there is a parameter called body. It should contain the form which can be reused to sent as an attachment
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: Tectite form, trying to email HTML form as HTM attachmen

Postby projectile » Wed Mar 20, 2013 5:00 am

Hi John
Thanks for your pointer,

I have added the "export variable content code" to the function at the bottom of this reply, and it appears to write the HTML code to a txt file, which is great. However is also outputs stuff at the top and bottom of the code, that doesn't render the HTML page correctly.

Is there any way to modify the code below to only output the variable contents that contains the HTML code (i.e. the text in red)?

Code: Select all
$file = 'c:/Inetpub/wwwroot/forms/techtite/fmtemplates/output1.txt';
$content = serialize($mesg);
file_put_contents($file, $content);
$content = unserialize(file_get_contents($file));





i.e. only output everything between

Content-Type: text/html; charset=ISO-8859-1 and --BODY ,

so only HTM code is outputted to output1.txt?

thanks


Contents of the variable that is outputted to output1.txt

s:7842:"(Your mail reader should not show this text.
If it does you may need to upgrade to more modern software.)

This message has been generated by FormMail using an HTML template
called "OSpayment_template.htm". The raw text of the form results
has been included below, but your mail reader should display the HTML
version only (unless it's not capable of doing so).

--BODY66a94a7645a86ae4f733abf5c0b52f2f
Content-Type: text/plain; charset=ISO-8859-1

email: john@domain.com
realname:
OS_AGENT_NAME:
OSAGENTCODE:
MEMBER: blank value
PARTNERPAY: blank
KNOWUNS:
ORIGIN:
VOLUME:
HISTORY:
TYPE:
CURRENCY:
AMOUNT:
ETA:
RENT:
INTENDED:
SALES:
PURCHASE:
COMMENTS:
HOWDEAL:
JOBREF:
requested_by: john
cfld1: q7ga
cfld2:

==================================

REMOTE_HOST=192.168.0.94
REMOTE_ADDR=192.168.0.94
HTTP_USER_AGENT=Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.1; .NET CLR 1.1.4322; InfoPath.2; Zune 4.7; .NET4.0C; .NET4.0E)
REMOTE_USER=DOMAIN\john

--BODY66a94a7645a86ae4f733abf5c0b52f2f
Content-Type: text/html; charset=ISO-8859-1

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Overseas agent payment decision Form</title>
<style>
html, body {
font-family: "Lucida Sans", Verdana, Helvetica, Arial, sans-serif;
font-size: small;
text-align: left;
}


table.outside
{border: 1px #6699CC solid;}
table.servicesT
{
border-collapse:collapse;
font-family: Verdana;
font-weight: normal;
font-size: 11px;
color: #404040;
width: 320px;
background-color: #fafafa;

margin-top: 0px;}


table.servicesT td.servHd
{ border-bottom: 2px solid #6699CC override;
background-color: #BEC8D1;
text-align: center;
font-family: Verdana;
font-weight: bold;
font-size: 11px;
color: #404040;}


table.servicesT td
{
border-bottom: 1px dotted #6699CC;
font-family: Verdana, sans-serif, Arial;
font-weight: normal;
font-size: 11px;
color: #404040;
background-color: white;
text-align: left;
padding-left: 3px;}

.servBodL { border-left: 1px dotted #CEDCEA; }
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
</style>





</head>
<body>


<table width="1" border="0" align="center" cellpadding="0" cellspacing="0" class="outside">
<tr>
<td><table width="753" align="center" class="servicesT">
<tr>
<td colspan="3" class="servHd"><h2><img src="http://www.domain.com/images/header-trans.gif" width="640" height="121" /><br />
OS Payment request Form</h2></td>
</tr>
<tr>
<td colspan="2"><div align="center"></div></td>
</tr>
<tr>
<td width="50%"> OS Agent Name *</td>
<td width="50%"></td>
</tr>
<tr>
<td> OS Agent Code *</td>
<td></td>
</tr>
<tr>
<td> COMPANY Member</td>
<td> blank value</td>
</tr>
<tr>
<td>If COMPANY can they make payment by PARTNER PAY?</td>
<td>blank</td>
</tr>
<tr>
<td><span class="927194512-03022011">
</span>
<div><span class="927194512-03022011"><font face="Arial"><font size="2">If no, how did they get our name? *</font></font></span></div>
<span class="927194512-03022011"></span></td>
<td></td>
</tr>
<tr>
<td><span class="927194512-03022011">
<div><span class="170012809-29012011"><font face="Arial"><font size="2">Country / Port of Loading / Destination</font></font></span>: * </div>
</span></td>
<td></td>
</tr>
<tr>
<td><span class="927194512-03022011"><span class="170012809-29012011">
<div><font size="2" face="Arial">Potential Volumes * </font></div>
</span></span></td>
<td></td>
</tr>
<tr>
<td><span class="927194512-03022011"><span class="170012809-29012011"><font size="2" face="Arial">Brief History of Previous Shipments * </font></span></span></td>
<td></td>
</tr>
<tr>
<td><span class="927194512-03022011"><span class="170012809-29012011"><font face="Arial"><font size="2">Current Shipment Type </font></font></span></span></td>
<td></td>
</tr>
<tr>
<td><span class="927194512-03022011">
<div><span class="170012809-29012011"><font face="Arial"><font size="2">Amount Payable * </font></font></span></div>
</span></td>
<td> </td>
</tr>
<tr>
<td><span class="927194512-03022011">
<div><span class="170012809-29012011"><font face="Arial"><font size="2"></font></font></span><font size="2"
face="Arial"><span class="170012809-29012011">ETA / ETD * </span></font></div>
</span></td>
<td></td>
</tr>
<tr>
<td><span class="927194512-03022011">
<div><font face="Arial"><font size="2"><span class="170012809-29012011">Rent Start Date * </span></font></font></div>
</span></td>
<td></td>
</tr>
<tr>
<td><span class="927194512-03022011">
<div><span class="170012809-29012011"></span><span class="170012809-29012011"><font
face="Arial"><font size="2">Intended Delivery / Shipment Date * </font></font></span></div>
</span></td>
<td></td>
</tr>
<tr>
<td><span class="927194512-03022011">
<div><font size="2" face="Arial"><span class="170012809-29012011">Outstanding Amounts of Sales Ledger * </span></font></div>
</span></td>
<td></td>
</tr>
<tr>
<td><span class="927194512-03022011">
<div><span class="170012809-29012011"></span><font size="2" face="Arial"><span
class="170012809-29012011">Outstanding Amounts of Purchase Ledger * </span></font></div>
</span></td>
<td></td>
</tr>
<tr>
<td><span class="927194512-03022011"><font size="2" face="Arial"><span class="170012809-29012011">Other Comments * </span></font></span></td>
<td></td>
</tr>
<tr>
<td>HOW DID WE DEAL WITH PAYMENT LAST TIME (IF APPLICABLE) *:<br /></td>
<td></td>
</tr>
<tr>
<td><font size="2" face="Arial, Helvetica, sans-serif">Job Ref * </font></td>
<td></td>
</tr>
<tr>
<td><font size="2" face="Arial, Helvetica, sans-serif">Requested By </font></td>
<td>john</td>
</tr>
</table></td>
</tr>
</table>
</form>

</body>
</html>

--BODY66a94a7645a86ae4f733abf5c0b52f2f--

";

For those who maybe interested , here is the function inside formmail.php where I added the "export variable content code"
Code: Select all

function SendCheckedMail($to,$subject,$mesg,$sender,$a_headers = array())
{
    global  $PEAR_SMTP_HOST;

$file = 'c:/Inetpub/wwwroot/forms/techtite/fmtemplates/output1.txt';
$content = serialize($mesg);
file_put_contents($file, $content);
$content = unserialize(file_get_contents($file));

    $b_f_option = false;
    $b_form_option = IsMailOptionSet("SendMailFOption");    // this is superseded, but still supported
    if (SENDMAIL_F_OPTION || $b_form_option)
    {
        if (empty($sender))
        {
                //
                // SENDMAIL_F_OPTION with no sender is silently ignored
                //
            if ($b_form_option)
            {
                    //
                    // form has specified SendMailFOption, but there's no
                    // sender address
                    //
                static  $b_in_here = false;
                global  $SERVER;

                if (!$b_in_here)        // prevent infinite recursion
                {
                    $b_in_here = true;
                    SendAlert(GetMessage(MSG_NO_FOPT_ADDR));
                    $b_in_here = false;
                }
                    //
                    // if there's no from address, create a dummy one
                    //
                $sender = "dummy@".(isset($SERVER) ? $SERVER : "UnknownServer");
                $a_headers['From'] = $sender;
                $b_f_option = true;
            }
        }
        else
            $b_f_option = true;
    }
projectile
New php-forum User
New php-forum User
 
Posts: 3
Joined: Tue Mar 19, 2013 12:38 pm

Re: Tectite form, trying to email HTML form as HTM attachmen

Postby seandisanti » Wed Mar 20, 2013 7:21 am

At the risk of over simplifying; if your goal is just to send the same email to a second recipient, why not just add a second recipient?
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: Tectite form, trying to email HTML form as HTM attachmen

Postby projectile » Wed Mar 20, 2013 7:32 am

The second email has specific requirements that is different to the first email, which is why BCC or CC wouldn't work;

i.e.
1. Subject is different
2. recepient is different
3. the completed form needs to be attached, and not placed into the body of the email

the second email goes to an unattended mailbox , where a scheduled script grabs the HTM attachment and stores in against a job file.

This is the reason why i need to do this.

Any ideas?
projectile
New php-forum User
New php-forum User
 
Posts: 3
Joined: Tue Mar 19, 2013 12:38 pm

Re: Tectite form, trying to email HTML form as HTM attachmen

Postby seandisanti » Wed Mar 20, 2013 8:02 am

Assuming that you only want the file to contain the information between the <html> and </html> tags, you should be able to parse the string prior to output using a regular expression. If you're not a fan of regular expressions, you could also use http://simplehtmldom.sourceforge.net/ to parse it.
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm


Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron