Reputation: 8463
Now we are using our own server to send email to our customers. its possible to send email using google server. how to do this. explain with php codes
Upvotes: 1
Views: 4865
Reputation: 405
Download PHPMailer from http://phpmailer.sourceforge.net Extract to folder phpmailer Create a file email.php Paste this code and change the values in blue as you need (I modified the sample code given on the PHPMailer homepage)
<?php
require("phpmailer/class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // send via SMTP
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "[email protected]"; // SMTP username
$mail->Password = "password"; // SMTP password
$webmaster_email = "[email protected]"; //Reply to this email ID
$email="[email protected]"; // Recipients email ID
$name="name"; // Recipient's name
$mail->From = $webmaster_email;
$mail->FromName = "Webmaster";
$mail->AddAddress($email,$name);
$mail->AddReplyTo($webmaster_email,"Webmaster");
$mail->WordWrap = 50; // set word wrap
$mail->AddAttachment("/var/tmp/file.tar.gz"); // attachment
$mail->AddAttachment("/tmp/image.jpg", "new.jpg"); // attachment
$mail->IsHTML(true); // send as HTML
$mail->Subject = "This is the subject";
$mail->Body = "Hi,
This is the HTML BODY "; //HTML Body
$mail->AltBody = "This is the body when user views in plain text format"; //Text Body
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent";
}
?>
Upvotes: 4
Reputation: 19380
function email($to, $subject, $body){
require_once("class.phpmailer.php");
$mail = new PHPMailer();
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->Username = "[email protected]";
$mail->Password = "password";
$mail->SetFrom("[email protected]", "Any Thing");
if(is_array($to)){
foreach($to as $t){
$mail->AddAddress($t);
}
}else{
$mail->AddAddress($to);
}
$mail->Subject = $subject;
$mail->Body = $body;
$mail->Send();
unset($mail);
}
Download http://phpmailer.sourceforge.net/ and name it "class.phpmailer.php"
Upvotes: 2
Reputation: 1189
http://micrub.info/2008/09/22/sending-email-with-zend_mail-using-gmail-smtp-services/ http://stackoverflow.com/questions/36079/php-mail-using-gmail
Upvotes: 0