wesley Posted November 15, 2015 Share Posted November 15, 2015 Hello, I have two things. I have phpmailer, he sent the content of the form to a E-mailaddress, this works. And I have phpword, he make word file, this also works. I have a question; how can I get the content of the form the $message (Full name, subject, phone, email and comments) in a word file in a Email attachment if you click on the submit button? With this code you see nothing in the browser. Can someone help me? thanks in advance. The form code is: <?php //phpword require_once '../PHPWord.php'; // New Word Document $PHPWord = new PHPWord(); // New portrait section $section = $PHPWord->createSection(); $section->addText($message, array('name'=>'Verdana', 'color'=>'006699')); $section->addTextBreak(2); // Save File $objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007'); $objWriter->save('Text.docx'); //phpmailer if(isset($_POST['submit'])) { $message= 'Full Name: '.$_POST['fullname'].'<br /> Subject: '.$_POST['subject'].'<br /> Phone: '.$_POST['phone'].'<br /> Email: '.$_POST['emailid'].'<br /> Comments: '.$_POST['comments'].' '; require "phpmailer/class.phpmailer.php"; //include phpmailer class // Instantiate Class $mail = new PHPMailer(); // Set up SMTP $mail->IsSMTP(); // Sets up a SMTP connection $mail->SMTPAuth = true; // Connection with the SMTP does require authorization $mail->SMTPSecure = "ssl"; // Connect using a TLS connection $mail->Host = "smtp.gmail.com"; //Gmail SMTP server address $mail->Port = 465; //Gmail SMTP port $mail->Encoding = '7bit'; // Authentication $mail->Username = "test@gmail.com"; // Your full Gmail address $mail->Password = "secret"; // Your Gmail password // Compose $mail->SetFrom($_POST['emailid'], $_POST['fullname']); $mail->AddReplyTo($_POST['emailid'], $_POST['fullname']); $mail->Subject = "form from website"; // Subject (which isn't required) $mail->MsgHTML($message); // Send To $mail->AddAddress("test@gmail.com", "form from website"); // Where to send it - Recipient $result = $mail->Send(); // Send! $message = $result ? 'Successfully Sent!' : 'Sending Failed!'; unset($mail); } ?> <!DOCTYPE HTML> <html lang="en"> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> </head> <body> <div style="margin: 100px auto 0;width: 300px;"> <h3>Contact Form</h3> <form name="form1" id="form1" action="" method="post"> <fieldset> <input type="text" name="fullname" placeholder="Full Name" required/> <br /> <input type="text" name="subject" placeholder="Subject" /> <br /> <input type="text" name="phone" placeholder="Phone" /> <br /> <input type="text" name="emailid" placeholder="Email" required/> <br /> <textarea rows="4" cols="20" name="comments" placeholder="Question/Comments"></textarea> <br /> <input type="submit" name="submit" value="Send" /> </fieldset> </form> <p><?php if(!empty($message)) echo $message; ?></p> </div> </body> </html> Link to comment Share on other sites More sharing options...
Chikwado Posted November 15, 2015 Share Posted November 15, 2015 If you are using phpmailer, then, in the folder called "examples" you will see a file called "code_generator.php" then, may be it will work for you. although don't know. Link to comment Share on other sites More sharing options...
justsomeguy Posted November 16, 2015 Share Posted November 16, 2015 Check the PHPWord documentation for how to add text and things to do the document, and check the PHPMailer documentation for how to attach a file. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now