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 = 'authorisedFrom@address.co.uk'; $to = 'to@address.co.uk'; $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('smtp.office365.com', 587, 'tls')) ->setUsername('authorisedFrom@address.co.uk') ->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:https://some-redirect.co.uk"); endif; ?>