Saturday, September 30, 2023
HomeQ&ASend Mail using Gmail in Wamp Server PHP

Send Mail using Gmail in Wamp Server PHP

Here in this post, we are discussing how the mail is sent from localhost or using the WAMP server in PHP. or also you can say how to send email using Gmail in PHP

Sometimes we have to check the send mail function from our development environment.

We can send the mail from our local host using WAMP by using some mail configuration by the WAMP server.

First of all, you need to enable the php_openssl PHP extension from php.ini. Here, I am talking about using the GMAIL SMTP server to send mail from the localhost and Sendmail package.

Sendmail is a mail transport agent which is placed in a php.ini file.

Sendmail package is inbuilt in the wamp server. If you are using wamp then you can easily send mail from localhost.

Here are some configuration parameters has given that are used in PHP mail.

  • Smtp_server: This shows the SMTP Host server name like smtp.hotmail.com, smtp.gmail.com, etc.
  • Smtp_port: This defines the port number like 465
  • Auth_username : your SMTP username
  • Auth_password  : your SMTP password

Steps to send email using gmail in php

You have to follow a few steps to send mail from the wamp server.

  • Step 1: you need to enable the php_openssl PHP extension for the PHP compiler in wamp.
  • That is shown in the image below

send mail php

send mail php

  • In Step 2: Find the mail function in the php.ini file, which is located in “C:\wamp\bin\apache\Apache2.4.9\bin\ you can show the code like below

send email using gmail in php - RKR Knowledge

  • Step 3: Replace your SMTP configuration parameters as below

send email using gmail in php in wamp server

Step 4:  Create a folder named Sendmail in “C:wamp\”.extract the file in sendmail folder named “libeay32.dll”,”ssleay32.dll” and “sendmail.ini”.

Open the sendmail.ini file and make some configurations given below :

[mail function]

Smtp_server = smtp.gmail.com

Smtp_port = 25

Auth_username = [email protected]

Auth_password = XXXXXX

Force_sender = [email protected]

Step 5: Restart your wamp server.

Create a PHP file and write the following code in it.

<?php
$to     = ‘[email protected]’;
$subject = ‘ send mail using wamp’;
$message = ‘Hi how are you?’;
$headers = ‘From : [your-gamil-account-username].com
                     ‘MIME – Version : 1.0’
                      ‘Content-type : text/html : charset = utf-8’;
If(mail($to , $subject ,$message, $headres))
       Echo “email sent”   
       Else :
        Echo “Email sendinf failed”;
?>

This is how you can send email using Gmail in PHP.

Read More:

Suhashini Mishra
Suhashini Mishrahttps://rkrknowledge.com/
Suhasini Mishra from India passionate UI UX Developer | Content Writer | Content Researcher | Ionic Developer

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -

Stay Connected

33FansLike
60FollowersFollow
520SubscribersSubscribe

Most Popular

Recent Comments