Can I use gmail as smtp server for my website

I successfully use the GMail SMTP server.

We do have a corporate GMail account, though I don't think that matters. A personal GMail account should suffice.

I do not have a PHP sample however the following configuration for ASP.Net should provide adequate guidance:

<mailSettings>
  <smtp from="[email protected]">
    <network enableSsl="true" host="smtp.gmail.com" port="587" userName="[email protected]" password="mypassword" />
  </smtp>
</mailSettings>

If someone has a suitable PHP sample, feel free to edit my answer or post your own.


Authentication is required I believe, but I don't see why not. I won't do the research for you, but there are a couple things to look into:

  • Their SMTP server requires TLS encryption and is hosted on a non-standard port (995). You will need to ensure that AWS supports both of these options for SMTP outbound.
  • There is probably a cap on emails you can send before being marked as spam. You should research this and ensure it is not beyond your requirements.

Yes, Google allows connections through their SMTP and allows you to send emails from your GMail account.

There are a lot of PHP mail scripts that you can use. Some of the most popular SMTP senders are: PHPMailer (with an useful tutorial) and SWIFTMailer (and their tutorial).

The data you need to connect and send emails from their servers are your GMail account, your password, their SMTP server (in this case smtp.gmail.com) and port (in this case 465) also you have to make sure that emails are being sent over SSL.

A quick example of sending an email like that with PHPMailer:

<?php
    require("class.phpmailer.php");

    $mail = new PHPMailer();

    $mail->IsSMTP();  // telling the class to use SMTP
    $mail->SMTPAuth   = true; // SMTP authentication
    $mail->Host       = "smtp.gmail.com"; // SMTP server
    $mail->Port       = 465; // SMTP Port
    $mail->Username   = "[email protected]"; // SMTP account username
    $mail->Password   = "your.password";        // SMTP account password

    $mail->SetFrom('[email protected]', 'John Doe'); // FROM
    $mail->AddReplyTo('[email protected]', 'John Doe'); // Reply TO

    $mail->AddAddress('[email protected]', 'Jane Doe'); // recipient email

    $mail->Subject    = "First SMTP Message"; // email subject
    $mail->Body       = "Hi! \n\n This is my first e-mail sent through Google SMTP using PHPMailer.";

    if(!$mail->Send()) {
      echo 'Message was not sent.';
      echo 'Mailer error: ' . $mail->ErrorInfo;
    } else {
      echo 'Message has been sent.';
    }
?>