PHP, MySQL, Drupal, .htaccess, Robots.txt, Phponwebsites: Send mail using php

11 Jun 2014

Send mail using php

                       You can send emails using php.

Mail() in php:


                       The mail() in php is used to send mail. The syndex for mail() is:

                    mail(to, subject, message, header)

Where,
            to - receiver mail id.
            subject - subject of mail.
            message - message to be sent.
            header - header of mail.

Note:
           You can send mail if you are in server. You've to make some changes in php.ini file, if you send mail from local server.

          You've to make following changes in your php.ini file to send mail.
                     [mail function]
                     ; For Win32 only.
                     ; http://php.net/smtp
                       SMTP =your ISP's mail server address
                     ; http://php.net/smtp-port
                       smtp_port = 25


                     ; For Win32 only.
                     ; http://php.net/sendmail-from
                       sendmail_from =example@gmail.com

How to send mail using php:


                      The following php script is used for send mail:

<?php
   $to='example@gmail.com';         
   $subject='Send mail using php';
   $message='This mail send using php';
   $headers='From: guruparthiban19@gmail.com';
   $mail=mail($to,$subject,$message,$headers);
   if($mail)
   {
    echo'Mail send successfully';
   }
   else
   {
    echo'Mail is not send';
   }
 ?>

                      If the the mail is send, then you'll get successful message. Otherwise you'll get 'Mail is not send' message. Now you can see mail in inbox.

3 comments:

  1. Thanks a lot .. helped me. Was getting stuck as was trying to send mail from a different mail account

    ReplyDelete
  2. Thanks a lot .. helped me. Was getting stuck as was trying to send mail from a different mail account

    ReplyDelete
  3. First of all i would like to say Thanks a lot for this great job.
    i have a problem in this program received a message Mail send successfully but mail does not show on the gmail account.Please help me.I am waiting you for valuable response.Thanks in advance.

    ReplyDelete