-1

I am trying to send mail to gmail account from my web site. It seems that everything is fine at the code level. Can you guys please look into this issue: even if i run this script, mail is not received to gmail Account.

 <?php
        if(isset($_POST['submit'])){
        ini_set('SMTP','localhost'); 
        $msg='Name : '.$_POST['name']."\n"
                .'Email : '.$_POST['email']."\n"
                .'Message : '.$_POST['message'];

                mail("aa@gmail.com","Message from Contact Us",$msg);
                     }

        else{
               echo 'cannot send email';
            }

        ?>
thor
  • 21,418
  • 31
  • 87
  • 173
Azhar Azmie
  • 29
  • 1
  • 4

1 Answers1

0

I think you will install phpmailer(http://pear.php.net/) and then send through smtp here is example code:

require_once "Mail.php";

$from = '<from@gmail.com>';
$to = '<to@yahoo.com>';
$subject = 'Hi!';
$body = "Hi,\n\nHow are you?";

$headers = array(
    'From' => $from,
    'To' => $to,
    'Subject' => $subject
);

$smtp = Mail::factory('smtp', array(
        'host' => 'ssl://smtp.gmail.com',
        'port' => '465',
        'auth' => true,
        'username' => 'your gmail ',
        'password' => 'your password'
    ));

$mail = $smtp->send($to, $headers, $body);

if (PEAR::isError($mail)) {
    echo('<p>' . $mail->getMessage() . '</p>');
} else {
    echo('<p>Message successfully sent!</p>');
user2110253
  • 317
  • 4
  • 12