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(docx) file in a Email attachment if you click on the submit button?
With this code you see nothing in the browser, how can I 'mix' phpmailer and phpword?.
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>