0

I'm a beginner with PHP, but I want to send mails to @yahoo.com, @gmail.com and another email addresses like these. I've read some tutorials, but I don`t have a SMTP server (I don't even know what is that), but I've read somewhere that it is possible to send via GMail (smtp.gmail.com). How is this possible ?

I'm running an Apache server on Windows 7.

Dave Jarvis
  • 30,436
  • 41
  • 178
  • 315
coolboycsaba
  • 183
  • 6
  • 14

4 Answers4

1

I have implemented msmtp.sourceforge.net within my Windows 7 environment combined with a google account, works like a dream.

The configuration file you'll need for Gmail is as follows:

A system wide configuration is optional.
     # If it exists, it usually defines a default account.
     # This allows msmtp to be used like /usr/sbin/sendmail.
     account default

     # The SMTP smarthost.
    host smtp.gmail.com
    domain smtp.gmail.com
    tls on
    tls_certcheck off
    tls_starttls on
    auth on
    user user@domain.co.uk
    from user@domain.co.uk
    password yourpasswordhere
    port 587
    logfile C:\msmtp\msmtplog.txt

     # Construct envelope-from addresses of the form "user@oursite.example".
     auto_from on
     maildomain user@domain.co.uk

Other information is available within the documentation provided for msmtp but in essence with the downloaded file, this configuration and a slight adjustment to the php.ini file you should be good to go.

simnom
  • 2,590
  • 1
  • 24
  • 34
0

use phpmailer class here is sample code for download phpmailer class goto http://sourceforge.net/projects/phpmailer/

    require('./class.phpmailer/class.phpmailer.php');
if(isset($_GET['name'])&&isset($_GET['email'])&&isset($_GET['message']))
{
define('GUSER', 'youremail@gmail.com'); // GMail username
define('GPWD', 'yourgmailpass'); // GMail password  


function smtpmailer($to, $from, $from_name, $subject, $body) { 
      global $error;
      $mail = new PHPMailer();  // create a new object
      $mail->IsSMTP(); // enable SMTP
      $mail->SMTPDebug = 0;  // debugging: 1 = errors and messages, 2 = messages only
      $mail->SMTPAuth = true;  // authentication enabled
      $mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
      $mail->Host = 'smtp.googlemail.com';
      $mail->Port = 465; 
      $mail->Username = GUSER;  
      $mail->Password = GPWD;           
      $mail->SetFrom($from, $from_name);
      $mail->Subject = $subject;
      $mail->Body = $body;
      $mail->AddAddress($to);
      if(!$mail->Send()) { echo 'error';}
     else{echo 'message send';}
}
$name="sender : ".$_GET['email']."";
    $message=$name."\n".$_GET['message'];
    $subject="a Message from :".$_GET['name'];

    smtpmailer('Destinationemail@yahoo.com', '', 'youremail@mail.com',$subject ,$message , $message); 
Afshin
  • 4,197
  • 3
  • 25
  • 34
0

Send email using the GMail SMTP server from a PHP page

Community
  • 1
  • 1
Adam Rabung
  • 5,232
  • 2
  • 27
  • 42
0

You can use PHPMailer to do it. Here is a tutorial

tHeSiD
  • 4,587
  • 4
  • 29
  • 49