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
Asked
Active
Viewed 4,856 times
3 Answers
4
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 = "username@gmail.com"; // SMTP username
$mail->Password = "password"; // SMTP password
$webmaster_email = "username@doamin.com"; //Reply to this email ID
$email="username@domain.com"; // 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";
}
?>

Matthew Strawbridge
- 19,940
- 10
- 72
- 93

dmag
- 405
- 2
- 7
-
where i need to place email.php file – Mohan Ram Dec 22 '10 at 13:50
-
Call to undefined function IsSMTP() in PHPMailer/email.php on line 5 Error Comes for me – Mohan Ram Dec 22 '10 at 13:56
-
Put it in the directory above the /phpmailer/ directory – dmag Dec 22 '10 at 13:57
-
Mailer Error: SMTP Error: Could not connect to SMTP host. This error comes for me. Did i need to change port number in class.smtp.php – Mohan Ram Dec 22 '10 at 14:04
-
I'm assuming you have replaced things like 'username@gmail.com'with your own gmail email address and password? – dmag Dec 22 '10 at 17:01
-
Open the file class.smtp.php in phpmailer directory Change the following lines: $host = "ssl://smtp.gmail.com"; $port = 465; – dmag Dec 22 '10 at 17:02
-
How to send to more than one. i need to send multiple email id – Mohan Ram Dec 23 '10 at 12:08
-
Original line 5, which @MohanRam mentions above -- `IsSMTP(); // send via SMTP` -- looks like a cut-and-paste error so I've removed it. – Matthew Strawbridge Apr 26 '13 at 22:03
2
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@domain.com";
$mail->Password = "password";
$mail->SetFrom("anything@domain.com", "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"

Dejan Marjanović
- 19,244
- 7
- 52
- 66
-
-
I edited my function, should work now, just pass $to as array of addresses like $to = array("you@you.com", "me@me.com", ... ) – Dejan Marjanović Dec 24 '10 at 12:39
0
http://micrub.info/2008/09/22/sending-email-with-zend_mail-using-gmail-smtp-services/ http://stackoverflow.com/questions/36079/php-mail-using-gmail

AmdY
- 1,179
- 8
- 5