Using SwiftMailer to deliver your own forms

1 posts by 1 authors in: Forums > CMS Builder Community
Last Post: September 3, 2018   (RSS)

By zaba - September 3, 2018

If you want to use the cmsb installation of SwiftMailer to send your forms via smtp you can add this to your form scripts.

Obviously you will need to customise it to your own requirements.

<?php //If your path is different edit below $swiftPath=$_SERVER['DOCUMENT_ROOT'].'/cmsb/3rdParty/SwiftMailer5/'; //Insert all form handling code here prior to submitting form if($allFormHandlingGood): $from = ''; $to = ''; $subject = "Subject Line of Email"; $message = "Message Details \n"; $message .= "$messageCombined \n"; require_once ($swiftPath.'swift_required.php'); // Create the Transport //if using office 365 (if not modify accordingly) $transport = (new Swift_SmtpTransport('', 587, 'tls')) ->setUsername('') ->setPassword('yourPassword') ; // Create the Mailer using your created Transport $mailer = new Swift_Mailer($transport); // Create a message $message = (new Swift_Message($subject)) ->setFrom([$from => 'From Company']) ->setTo([$to => 'Name Surname']) ->setBody($message) ; // Send the message $result = $mailer->send($message); header("Location:"); endif; ?>