Forgot your password?


How to send e-mails via SMTP with PHPmailer and Gmail?


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?

  1. If you don’t have one, register a Gmail account or setup your domain for Google applications.
  2. Download the most recent version of PHPMailer
  3. Extract the PHPMailer packages to a folder named phpmailer and upload that folder to your XtreemHost hosting account (using FTP)
  4. 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");
  5. Now, include the below code and edit it with your Gmail account details:
    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://";
    $mail->Port = 465;
    $mail->SMTPAuth = true; // turn on SMTP authentication
    $mail->Username = ""; // 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.';
  6. 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.

This entry was posted in News, Uncategorized and tagged , , , . Bookmark the permalink.
  • Ambika

    Message could not be sent.Mailer Error: SMTP connect() failed. error occur

  • Facing this problem.
    SMTP Error: Could not connect to SMTP host. Message was not sent.Mailer error

  • rishad

    Message could not be sent.Mailer Error: SMTP connect() failed.

  • rishad

    how i solve this?

  • xtreemhost

    This only works on the premium plan. Free hosting does not offer remote SMTP.

  • xtreemhost

    I’m sorry, but this only works on the premium plan. Free hosting does not offer remote SMTP.

  • kamal



    SMTP connect() failed.



    An error was encountered while sending the registration email. A message has been sent to the administrator of this site.

  • Rushabh Patel

    help me in this…

    2016-06-23 10:23:21 SMTP ERROR: Failed to connect to server: Connection refused (111)
    2016-06-23 10:23:21 SMTP connect() failed.
    Message was not sent.Mailer error: SMTP connect() failed.