lundi 30 mars 2015

Swiftmailer file attachment for on the fly emails

I am trying to integrate a swiftmailer form instance, below is the code





<form name="filer" method="post" ENCTYPE="multipart/form-data" action="/scripts/send-file.php">

<h2>Upload Your Resume</h2>
<input type="text" name="Name" id="Name" placeholder="Full Name*" />

<input type="email" name="Email" id="Email" placeholder="Email Address*" />

<input type="number" name="Contact" id="Contact" placeholder="Contact No.*" />

<textarea name="Address" rows="20" cols="20" id="Address" placeholder="Address"></textarea>

<input type="text" name="Pin" id="Pin" placeholder="Pin-Code"/>

<input type="text" name="City" id="City" placeholder="City*"/>

<input type="text" name="State" id="State" placeholder="State*" />

<input type="file" name="Attachment" id="Attachment" placeholder="Attach File*" required/>

<div class="contact_wrapper">
<input type="submit" name="book_form" value="Submit" class="sixth before after book"/>
</div>
</form>




require_once 'lib/swift_required.php';
// Create the Transport the call setUsername() and setPassword()
$transport = Swift_SmtpTransport::newInstance('mail.dcai.co.in', '25')
->setUsername('mailer@dcai.co.in')
->setPassword('t1;AGd]');
// Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);

);
// Create the message
$message = Swift_Message::newInstance()
// Give the message a subject
->setSubject('Attachment Website - Website')
// Set the From address with an associative array
->setFrom(array('mailer@dcavanti.co.in' => 'DC ANTI'))
// Set the To addresses with an associative array
->setTo(array('flair_n@live.com', 'n007@gmail.com' => 'A name'))
// Give it a body
->setBody('<p style="line-height:10px;">
<b>Book Your Avanti- Person Details</b><hr>
<br/><b>Name:</b> ' .$name . '<br><br> '
.'<b>Email:</b> ' .$email . '<br><br> '
.'<b>Contact:</b> ' .$contact . '<br><br> '
.'<b>Address:</b> ' .$address . '<br><br> '
.'<b>Pin:</b> ' .$pin . '<br><br> '
.'<b>City:</b> ' .$city . '<br><br> '
.'<b>State:</b> ' .$state . '<br><br><hr /> ', 'text/html')
//Attaching the file
->attach(Swift_Attachment::fromPath($attachment))
// Sending the mail
if ($mailer->send($message))
{
header('Location: landing_file.php');
}
else
{
echo "Failed\n";
}


I am looking for uploading option which checks for pdf and word file and send it directly through email attachment using swiftmailer. The documentation didn't gave instructions to perform any check and neither i got successful in send a file even without it.


Aucun commentaire:

Enregistrer un commentaire