"can i use gmail as smtp server for my website" Code Answer


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:


    $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   = "john.doe@gmail.com"; // smtp account username
    $mail->password   = "your.password";        // smtp account password

    $mail->setfrom('john.doe@gmail.com', 'john doe'); // from
    $mail->addreplyto('john.doe@gmail.com', 'john doe'); // reply to

    $mail->addaddress('jane.doe@gmail.com', 'jane doe'); // recipient email

    $mail->subject    = "first smtp message"; // email subject
    $mail->body       = "hi! nn 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.';
By Philipp Herzig on October 20 2022

Answers related to “can i use gmail as smtp server for my website”

Only authorized users can answer the Search term. Please sign in first, or register a free account.