Jump to content

Generating XML from an html form and sending an attachment to e-mail


superzoom

Recommended Posts

Hi, I have a simple html form.

<form action="mail.php" method="POST">
<p>Name</p> <input type="text" name="name">
<p>Email</p> <input type="text" name="email">
<p>Phone</p> <input type="text" name="phone">
 
<p>Message</p><textarea name="message" rows="6" cols="25"></textarea><br />
<input type="submit" value="Send"><input type="reset" value="Clear">
</form>

I send a simple recap to e-mail through PHP. Simultaneously with this recapitulation, I would like to generate XML, which would send it in an e-mail attachment. Somehow it's not working. Would anyone help?

<?php
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$formcontent=" From: $name \n Phone: $phone \n Call Back: $call \n Website: $website \n Priority: $priority \n Type: $type \n Message: $message";
$recipient = "**************";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
 
$doc = new DOMDocument('1.0', 'UTF-8');
$doc->formatOutput = true;
 
$xmlRoot = $doc->createElement("xml");
$xmlRoot = $doc->appendChild($xmlRoot);
$root = $doc->createElement('OrderDetails');
$root = $doc->appendChild($root);
 
$ele1 = $doc->createElement('name');
$ele1->nodeValue=$name;
$root->appendChild($ele1);
 
$xml->saveXML("");
 
$mail->addStringAttachment($xml->asXML(), "xml.xml");
 
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!" . " -" . "<a href='form.html' style='text-decoration:none;color:#ff0099;'> Return Home</a>";
?>

Thanks for any help!!

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.