Web Wiz - Solar Powered Eco Web Hosting


Sending Mail Using PHP with SwiftMailer 6


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



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 "[email protected]" and the password where it has "YourPasswordHere" in the example below.

If you are sending email from a "Contact Us" form on your website you may wish to use the website visitors address when replying to teh email. For this you would set a "ReplyTo" address with the visitors email address where you see "[email protected]"


<?php

require_once 'autoload.php';


$host = "smtp.websitelive.net";
$port = 587;
$username = "[email protected]";
$password = "YourPasswordHere";


$from = "[email protected]";
$to = "[email protected]";
$replyto = "[email protected]";


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

$transport = new Swift_SmtpTransport($host, $port, 'tls');
$transport->setUsername($username)->setPassword($password);

$swift = new Swift_Mailer($transport);

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

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 X Connect with us on LinkedIn Web Wiz Blogs
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: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

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

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