Web Wiz
  Knowledgebase Knowledgebase      Customer Login Customer Login

EmailSending Mail Using PHP with SwiftMailer


Below you will find an example of sending email from your Web Wiz Hosted Website using PHP and SwiftMailer.



In order to send email you will first need to Setup a Mailbox from your Hosting Control Panel to use to send your email.

You would then enter the email address for your mailbox where it has "you@your-email-here.com" and the password where it has "YourPasswordHere" in the example below.


<?php

require_once 'swift_required.php';


$host = "smtp.websitelive.net";
$port = 587;
$username = "you@your-email-here.com";
$password = "YourPasswordHere";


$from = "you@your-email-here.com";
$to = "to@to-email-here.com";


$subject = "Hi!";
$body = "Hi,\n\n Test from my website";


$transport = Swift_SmtpTransport::newInstance()

->setHost($host)
->setPort($port)
->setEncryption('tls')
->setUsername($username)
->setPassword($password)
;

$swift = Swift_Mailer::newInstance($transport);

$message = new Swift_Message($subject);
$message->setFrom($from);
$message->setBody($body, 'text/html');
$message->setTo($to);

if ($recipients = $swift->send($message, $failures))
{
         echo("<p>Message successfully sent!</p>");
} else {
         echo("<p>There was an error!</p>");
          print_r($failures);
}

?>


Back To Hosting Knowledgebase Menu


Become a Fan on Facebook Follow us on Twitter Find us on Google+ Community Forums Web Wiz Blogs Web Wiz News
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Policy

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Unit B10, 9 Nimrod Way, East Dorset Trade Park, Wimborne, Dorset, BH21 7UH, United Kingdom.

Prices exclude VAT unless otherwise stated. VAT No. 988999105 - $, € prices shown as a guideline only.


Copyright ©2001-2016 Web Wiz Ltd. All rights reserved.