superzoom Posted April 20, 2021 Share Posted April 20, 2021 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!! Quote Link to comment https://forums.phpfreaks.com/topic/312518-generating-xml-from-an-html-form-and-sending-an-attachment-to-e-mail/ Share on other sites More sharing options...
gw1500se Posted April 20, 2021 Share Posted April 20, 2021 "Its not working" is NOT a helpful description. What is the error, if any? What is it doing different than you expect? Do you have error reporting turned on? Is there any errors in your httpd log? Quote Link to comment https://forums.phpfreaks.com/topic/312518-generating-xml-from-an-html-form-and-sending-an-attachment-to-e-mail/#findComment-1586000 Share on other sites More sharing options...
superzoom Posted April 20, 2021 Author Share Posted April 20, 2021 The section for generating XML and attaching to an e-mail attachment does not work. I am a beginner and i will supply what is needed. Quote Link to comment https://forums.phpfreaks.com/topic/312518-generating-xml-from-an-html-form-and-sending-an-attachment-to-e-mail/#findComment-1586001 Share on other sites More sharing options...
Barand Posted April 20, 2021 Share Posted April 20, 2021 You are creating an XML document in $doc, then right at the end, you decide to reference it as $xml instead of $doc. Quote Link to comment https://forums.phpfreaks.com/topic/312518-generating-xml-from-an-html-form-and-sending-an-attachment-to-e-mail/#findComment-1586004 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.