How to send e-mails via SMTP with PHPmailer and Gmail?
Introduction
Lately, we’re receiving a lot of support questions regarding the use of Gmail SMTP on the free hosting plan. With Gmail SMTP you can send mails from your website without using the default PHP Sendmail. You can use it for your forums, online contact forms etc… In this tutorial, we will explain you the benefits of using Gmail SMTP and give you a tutorial how you can use it in your PHP pages hosted at XtreemHost!
Why using Gmail for sending mail messages?
First of all it’s FREE! Sure most website owners can use their own SMTP server for sending email messages from their website, but it makes sense even than to use Gmail for sending mail. The chance is big that your websites IP address is on a blacklist if your site is on hosted by a shared web hosting provider. If not or you host your site on your own server, there is always a risk that your IP address get blacklisted. Because of some limitations, the SMTP server from Google is a good choice applications with less than 500 recipients a day, check this information from the Google help pages. Furthermore, our free hosting plan meets all requirements to use Google SMTP without problems.
Tutorial: How to setup SMTP for Gmail?
- If you don’t have one, register a Gmail account or setup your domain for Google applications.
- Download the most recent version of PHPMailer
- Extract the PHPMailer packages to a folder named phpmailer and upload that folder to your XtreemHost hosting account (using FTP)
- Include the phpmailer class file in the page that will send an email. Just include following code in your PHP page:
require("class.phpmailer.php");
- Now, include the below code and edit it with your Gmail account details:
<?php require("class.phpmailer.php"); // path to the PHPMailer class $mail = new PHPMailer(); $mail->IsSMTP(); // telling the class to use SMTP $mail->Mailer = "smtp"; $mail->Host = "ssl://smtp.gmail.com"; $mail->Port = 465; $mail->SMTPAuth = true; // turn on SMTP authentication $mail->Username = "yourusername@gmail.com"; // SMTP username $mail->Password = "yourpassword"; // SMTP password $mail->From = "email address sender"; $mail->AddAddress("email address receiver"); $mail->Subject = "First PHPMailer Message"; $mail->Body = "Hi! \n\n This is my first e-mail sent through PHPMailer."; $mail->WordWrap = 50; if(!$mail->Send()) { echo 'Message was not sent.'; echo 'Mailer error: ' . $mail->ErrorInfo; } else { echo 'Message has been sent.'; } ?>
- Test the page you created and see if the email is sent successfully.
We hope this small tutorial will help everyone that is facing problems with the default PHP Sendmail option that we provide.
Log in
Premium Info
Did you know the premium plan comes with unlimited features (webspace, bandwidth, email accounts etc.), no restrictions (cURL, Sockets, Sendmail etc.), a Website Builder, Shopping Cart tools and a FREE Domain Name?
Compare our free and premium hosting plan.
Recent Comments