Reputation: 183
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.
Upvotes: 0
Views: 4054
Reputation: 4215
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', '[email protected]'); // 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('[email protected]', '', '[email protected]',$subject ,$message , $message);
Upvotes: 0
Reputation: 2620
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 [email protected]
from [email protected]
password yourpasswordhere
port 587
logfile C:\msmtp\msmtplog.txt
# Construct envelope-from addresses of the form "[email protected]".
auto_from on
maildomain [email protected]
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.
Upvotes: 1