Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    May 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PHP Form to XML Attachment

    I have created a php form and have the form sending me an email with the xml attachment but the XML attachment does not have the information in?

    <?php

    $xmlDoc = new DOMDocument('1.0');

    $xmlRoot = $xmlDoc->createElement('AllData');
    $xmlDoc->appendChild($xmlRoot);

    $xmlIndividual = $xmlDoc->createElement('Individual');

    $contact_name = $_POST["contact_name"];
    $contact_email = $_POST["contact_email"];
    $contact_phone = $_POST["contact_phone"];
    $contact_message = $_POST["contact_message"];

    $xmlname = $xmlDoc->createElement('contact_name', $contact_name);
    $xmlIndividual->appendChild($xmlname);


    $xmlemail_address = $xmlDoc->createElement('contact_email', $contact_email);
    $xmlIndividual->appendChild($xmlemail_address);


    $xmlphone = $xmlDoc->createElement('contact_phone', $contact_phone);
    $xmlIndividual->appendChild($xmlphone);


    $xmlmessage = $xmlDoc->createElement('contact_message', $contact_message);
    $xmlIndividual->appendChild($xmlmessage);

    $content = $xmlDoc->saveXML();

    if (!isset($_POST['save']) || $_POST['save'] != 'contact') {
    header('Location: contact.php'); exit;
    }

    // get the posted data
    $name = $_POST['contact_name'];
    $email_address = $_POST['contact_email'];
    $phone = $_POST['contact_phone'];
    $message = $_POST['contact_message'];

    if (empty($name))
    $error = 'You must enter your name.';
    elseif (empty($email_address))
    $error = 'You must enter your email address.';
    elseif (!preg_match('/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/', $email_address))
    $error = 'You must enter a valid email address.';
    if (empty($phone))
    $error = 'You must enter your phone number.';
    elseif (empty($message))
    $error = 'You must enter a message.';

    if (isset($error)) {
    header('Location: contact.php?e='.urlencode($error)); exit;
    }


    $email_content = "Name: $name\n";
    $email_content .= "Email Address: $email_address\n";
    $email_content .= "Phone Number: $phone\n";
    $email_content .= "Message:\n\n$message";

    mail_attachment('becky.king99@gmail.com', 'Westover', $email_content, $email_address, $content, 'test2.xml');

    header('Location: contact.html?s='.urlencode('Thank you for your message.')); exit;

    function mail_attachment($to, $subject, $message, $from, $data, $test2) {
    $content = chunk_split(base64_encode($data));
    $uid = md5(uniqid(time()));
    $from = str_replace(array("\r", "\n"), '', $from); // to prevent email injection
    $header = "From: ".$from."\r\n"
    ."MIME-Version: 1.0\r\n"
    ."Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n"
    ."This is a multi-part message in MIME format.\r\n"
    ."--".$uid."\r\n"
    ."Content-type:text/plain; charset=iso-8859-1\r\n"
    ."Content-Transfer-Encoding: 7bit\r\n\r\n"
    .$message."\r\n\r\n"
    ."--".$uid."\r\n"
    ."Content-Type: application/octet-stream; name=\"".$test2."\"\r\n"
    ."Content-Transfer-Encoding: base64\r\n"
    ."Content-Disposition: attachment; filename=\"".$test2."\"\r\n\r\n"
    .$content."\r\n\r\n"
    ."--".$uid."--";
    return mail($to, $subject, "", $header);
    }
    ?>

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,295
    Thanks
    23
    Thanked 611 Times in 610 Posts
    Line 53
    if (isset($error)) {
    header('Location: contact.php?e='.urlencode($errorexit;
    }

    Not right
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • #3
    New to the CF scene
    Join Date
    May 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    What should it be?

  • #4
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,303
    Thanks
    4
    Thanked 204 Times in 201 Posts
    Notice the 2 missing closing parenthesis on that line.
    Dave .... HostMonster for all of your hosting needs

  • #5
    New to the CF scene
    Join Date
    May 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have fixed that but the XML attachment still does not contain the information from the form? Really need this to work soon!!!

  • #6
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,295
    Thanks
    23
    Thanked 611 Times in 610 Posts
    Did you remove the semicolon:
    S/B header('Location: contact.php?e=' . urlencode($errorexit));
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •