homepage Welcome to WebmasterWorld Guest from 54.167.10.244
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Php email form to XML attachment?
Php email form to XML attachment?
kurazi




msg:4122995
 4:48 pm on Apr 27, 2010 (gmt 0)

Hi there,

A client of mine has asked me to make them a form for their website, which I have completed without any issues. It emails them the information from the form, but now they are asking me if I can make it so it emails them it in a XML attachment so they can use it to import the data into this software they are using. I do not know anything about XML, and I only know basic PHP. I wonder if anyone can me some pointers on what I need to do from here. Here is the code I used for the form.



<?php
if ($_SERVER['REQUEST_METHOD'] != 'POST'){
$me = $_SERVER['PHP_SELF'];

?>
<form name="form1" method="post"
action="<?php echo $me;?>">

<form>.....</form>



<?php
} else {
error_reporting(0);
$recipient = 'contact@example.com';
$in_name = stripslashes($_POST['i_name']);
$la_name = stripslashes($_POST['l_name']);
$in_street = stripslashes($_POST['i_street']);
$in_city_prov = stripslashes($_POST['i_city_prov']);
$in_pcode = stripslashes($_POST['i_pcode']);
$in_phone = stripslashes($_POST['i_phone']);
$brokerage = stripslashes($_POST['brokerage']);
$br_street = stripslashes($_POST['b_street']);
$br_city_prov = stripslashes($_POST['b_city_prov']);
$br_pcode = stripslashes($_POST['b_pcode']);
$br_phone = stripslashes($_POST['b_phone']);
$ext = stripslashes($_POST['ext']);
$br_con_nam = stripslashes($_POST['b_con_nam']);
$br_con_email = stripslashes($_POST['b_con_email']);
$financed = stripslashes($_POST['p_financed']);
$p_num1 = stripslashes($_POST['pol_num1']);
$mon1 = stripslashes($_POST['month1']);
$day1 = stripslashes($_POST['day1']);
$yr1 = stripslashes($_POST['year1']);
$ins_com1 = stripslashes($_POST['ins_com1']);
$type1 = stripslashes($_POST['type1']);
$t_mon_yr1 = stripslashes($_POST['term_mon_yr1']);
$prem1 = stripslashes($_POST['premium1']);
$fee1 = stripslashes($_POST['fees1']);
$cfee1 = stripslashes($_POST['cfees1']);
$tax1 = stripslashes($_POST['tax1']);
$p_num2 = stripslashes($_POST['pol_num2']);
$mon2 = stripslashes($_POST['month2']);
$day2 = stripslashes($_POST['day2']);
$yr2 = stripslashes($_POST['year2']);
$ins_com2 = stripslashes($_POST['ins_com2']);
$type2 = stripslashes($_POST['type2']);
$t_mon_yr2 = stripslashes($_POST['term_mon_yr2']);
$prem2 = stripslashes($_POST['premium2']);
$fee2 = stripslashes($_POST['fees2']);
$cfee2 = stripslashes($_POST['cfees2']);
$tax2 = stripslashes($_POST['tax2']);
$p_num3 = stripslashes($_POST['pol_num3']);
$mon3 = stripslashes($_POST['month3']);
$day3 = stripslashes($_POST['day3']);
$yr3 = stripslashes($_POST['year3']);
$ins_com3 = stripslashes($_POST['ins_com3']);
$type3 = stripslashes($_POST['type3']);
$t_mon_yr3 = stripslashes($_POST['term_mon_yr3']);
$prem3 = stripslashes($_POST['premium3']);
$fee3 = stripslashes($_POST['fees3']);
$cfee3 = stripslashes($_POST['cfees3']);
$tax3 = stripslashes($_POST['tax3']);
$p_num4 = stripslashes($_POST['pol_num4']);
$mon4 = stripslashes($_POST['month4']);
$day4 = stripslashes($_POST['day4']);
$yr4 = stripslashes($_POST['year4']);
$ins_com4 = stripslashes($_POST['ins_com4']);
$type4 = stripslashes($_POST['type4']);
$t_mon_yr4 = stripslashes($_POST['term_mon_yr4']);
$prem4 = stripslashes($_POST['premium4']);
$fee4 = stripslashes($_POST['fees4']);
$cfee4 = stripslashes($_POST['cfees4']);
$tax4 = stripslashes($_POST['tax4']);
$p_num5 = stripslashes($_POST['pol_num5']);
$mon5 = stripslashes($_POST['month5']);
$day5 = stripslashes($_POST['day5']);
$yr5 = stripslashes($_POST['year5']);
$ins_com5 = stripslashes($_POST['ins_com5']);
$type5 = stripslashes($_POST['type5']);
$t_mon_yr5 = stripslashes($_POST['term_mon_yr5']);
$prem5 = stripslashes($_POST['premium5']);
$fee5 = stripslashes($_POST['fees5']);
$cfee5 = stripslashes($_POST['cfees5']);
$tax5 = stripslashes($_POST['tax5']);
$p_num6 = stripslashes($_POST['pol_num6']);
$mon6 = stripslashes($_POST['month6']);
$day6 = stripslashes($_POST['day6']);
$yr6 = stripslashes($_POST['year6']);
$ins_com6 = stripslashes($_POST['ins_com6']);
$type6 = stripslashes($_POST['type6']);
$t_mon_yr6 = stripslashes($_POST['term_mon_yr6']);
$prem6 = stripslashes($_POST['premium6']);
$fee6 = stripslashes($_POST['fees6']);
$cfee6 = stripslashes($_POST['cfees6']);
$tax6 = stripslashes($_POST['tax6']);
$p_num7 = stripslashes($_POST['pol_num7']);
$mon7 = stripslashes($_POST['month7']);
$day7 = stripslashes($_POST['day7']);
$yr7 = stripslashes($_POST['year7']);
$ins_com7 = stripslashes($_POST['ins_com7']);
$type7 = stripslashes($_POST['type7']);
$t_mon_yr7 = stripslashes($_POST['term_mon_yr7']);
$prem7 = stripslashes($_POST['premium7']);
$fee7 = stripslashes($_POST['fees7']);
$cfee7 = stripslashes($_POST['cfees7']);
$tax7 = stripslashes($_POST['tax7']);
$p_num8 = stripslashes($_POST['pol_num8']);
$mon8 = stripslashes($_POST['month8']);
$day8 = stripslashes($_POST['day8']);
$yr8 = stripslashes($_POST['year8']);
$ins_com8 = stripslashes($_POST['ins_com8']);
$type8 = stripslashes($_POST['type8']);
$t_mon_yr8 = stripslashes($_POST['term_mon_yr8']);
$prem8 = stripslashes($_POST['premium8']);
$fee8 = stripslashes($_POST['fees8']);
$cfee8 = stripslashes($_POST['cfees8']);
$tax8 = stripslashes($_POST['tax8']);


$headers = "From: $br_con_email\r\n\r\n";
$subject = "Quick Quote Form from Website";
$message = "First Name: $in_name\r\n
Last Name: $la_name\r\n
Insured Street Address: $in_street\r\n
Insured City & Province: $in_city_prov\r\n
Insured Postal Code: $in_pcode\r\n
Insured Phone Number: $in_phone\r\n
Brokerage: $brokerage\r\n
Broker Street Address: $br_street\r\n
Broker City & Province: $br_city_prov\r\n
Broker Postal Code: $br_pcode\r\n
Broker Phone Number: $br_phone\r\n
Broker Phone Ext: $ext\r\n
Broker Name: $br_con_nam\r\n
Broker Email: $br_con_email\r\n
Policy Number: $p_num1 Effective Date: $mon1 $day1 $yr1 Ins. Company: $ins_com1 Type Of Coverage: $type1 Term: $t_mon_yr1 Policy Premium: $prem1 Policy Fee: $fee1 Company Fee: $cfee1 Sales Tax: $tax1 \r\n
Policy Number: $p_num2 Effective Date: $mon2 $day2 $yr2 Ins. Company: $ins_com2 Type Of Coverage: $type2 Term: $t_mon_yr2 Policy Premium: $prem2 Policy Fee: $fee2 Company Fee: $cfee2 Sales Tax: $tax2 \r\n
Policy Number: $p_num3 Effective Date: $mon3 $day3 $yr3 Ins. Company: $ins_com3 Type Of Coverage: $type3 Term: $t_mon_yr3 Policy Premium: $prem3 Policy Fee: $fee3 Company Fee: $cfee3 Sales Tax: $tax3 \r\n
Policy Number: $p_num4 Effective Date: $mon4 $day4 $yr4 Ins. Company: $ins_com4 Type Of Coverage: $type4 Term: $t_mon_yr4 Policy Premium: $prem4 Policy Fee: $fee4 Company Fee: $cfee4 Sales Tax: $tax4 \r\n
Policy Number: $p_num5 Effective Date: $mon5 $day5 $yr5 Ins. Company: $ins_com5 Type Of Coverage: $type5 Term: $t_mon_yr5 Policy Premium: $prem5 Policy Fee: $fee5 Company Fee: $cfee5 Sales Tax: $tax5 \r\n
Policy Number: $p_num6 Effective Date: $mon6 $day6 $yr6 Ins. Company: $ins_com6 Type Of Coverage: $type6 Term: $t_mon_yr6 Policy Premium: $prem6 Policy Fee: $fee6 Company Fee: $cfee6 Sales Tax: $tax6 \r\n
Policy Number: $p_num7 Effective Date: $mon7 $day7 $yr7 Ins. Company: $ins_com7 Type Of Coverage: $type7 Term: $t_mon_yr7 Policy Premium: $prem7 Policy Fee: $fee7 Company Fee: $cfee7 Sales Tax: $tax7 \r\n
Policy Number: $p_num8 Effective Date: $mon8 $day8 $yr8 Ins. Company: $ins_com8 Type Of Coverage: $type8 Term: $t_mon_yr8 Policy Premium: $prem8 Policy Fee: $fee8 Company Fee: $cfee8 Sales Tax: $tax8 \r\n


";
mail($recipient, $subject, $message, $headers);
if (!mail) {
echo "Message failed to send";
} else {
echo nl2br ("<center><br><br><br><br><br><br><br><br><br><br>Thank you. Your request has been sent and we will contact you shortly.<br><br><br><br><br><br><br><br><br><br></center>");
}
}
?>

[edited by: eelixduppy at 9:06 pm (utc) on Apr 28, 2010]
[edit reason] exemplified [/edit]

 

eelixduppy




msg:4123977
 9:11 pm on Apr 28, 2010 (gmt 0)

How are you doing with this?

Google has plenty of examples on how to add attachments using PHP, if I were you I'd so a quick search.

You can also use the PEAR package (or other similar libraries): [pear.php.net...]

kurazi




msg:4124612
 8:06 pm on Apr 29, 2010 (gmt 0)

Not very good :( I have searched google, but I think that it may just go behond my knowledge, or at least from what I have found. Do you know of any simple solutions for this?

kurazi




msg:4124613
 8:07 pm on Apr 29, 2010 (gmt 0)

They have advised me it must be XML as they need it to easily update a database they use for their software.

jatar_k




msg:4124930
 2:10 pm on Apr 30, 2010 (gmt 0)

xml is essentially just a structure, so if they can give you an example of the format the file needs then you would just have to look at a single entry, which can be quite large, and then replicate that format.

you need to map your data to the places it needs to be in the xml

not hard, get them to give you a sample file then you can go from there

you could even save it to a database and give them a method for generating it, but that is just an idea and is out of scope of this project if there isn't already a database in use

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved