nkrueger84
asked on
How to send email through hosted gmail account
I'm trying to send mail using a contact us form from our hosted gmail account. For example, our account is support@mydomain.com and we are using hosted gmail for email.
I need an email script written in PHP that will send mail from our hosted gmail account. I know know it has to authenticated to gmails servers, but I have yet to find a working script. The SMTP authentication enable scripts I have tested will not work with a hosted gmail account.
Please refer me to a script that works or post the code here if possible. I would really appreciate it - I'm completely stuck.
Thank you!
I need an email script written in PHP that will send mail from our hosted gmail account. I know know it has to authenticated to gmails servers, but I have yet to find a working script. The SMTP authentication enable scripts I have tested will not work with a hosted gmail account.
Please refer me to a script that works or post the code here if possible. I would really appreciate it - I'm completely stuck.
Thank you!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
i am sorry this is the right code
<?php
//error_reporting(E_ALL);
error_reporting(E_STRICT);
date_default_timezone_set( 'America/T oronto');
include("class.phpmailer.p hp");
//include("class.smtp.php" ); // optional, gets called from within class.phpmailer.php if not already loaded
$mail = new PHPMailer();
$body = $mail->getFile('contents.h tml');
$body = eregi_replace("[\]",'',$bo dy);
$mail->IsSMTP();
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = "yourusername@gmail.com"; // GMAIL username
$mail->Password = "yourpassword"; // GMAIL password
$mail->AddReplyTo("youruse rname@gmai l.com","Fi rst Last");
$mail->From = "name@yourdomain.com";
$mail->FromName = "First Last";
$mail->Subject = "PHPMailer Test Subject via gmail";
//$mail->Body = "Hi,<br>This is the HTML BODY<br>"; //HTML Body
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->WordWrap = 50; // set word wrap
$mail->MsgHTML($body);
$mail->AddAddress("whoto@o therdomain .com", "John Doe");
$mail->AddAttachment("imag es/phpmail er.gif"); // attachment
$mail->IsHTML(true); // send as HTML
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
<?php
//error_reporting(E_ALL);
error_reporting(E_STRICT);
date_default_timezone_set(
include("class.phpmailer.p
//include("class.smtp.php"
$mail = new PHPMailer();
$body = $mail->getFile('contents.h
$body = eregi_replace("[\]",'',$bo
$mail->IsSMTP();
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = "yourusername@gmail.com"; // GMAIL username
$mail->Password = "yourpassword"; // GMAIL password
$mail->AddReplyTo("youruse
$mail->From = "name@yourdomain.com";
$mail->FromName = "First Last";
$mail->Subject = "PHPMailer Test Subject via gmail";
//$mail->Body = "Hi,<br>This is the HTML BODY<br>"; //HTML Body
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->WordWrap = 50; // set word wrap
$mail->MsgHTML($body);
$mail->AddAddress("whoto@o
$mail->AddAttachment("imag
$mail->IsHTML(true); // send as HTML
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
You may also configure your server so that mail actually is configured to use google as your stmp.
Try this: http://laurentbois.com/2007/10/20/activemailer-using-msmtp-and-gmail/
Try this: http://laurentbois.com/2007/10/20/activemailer-using-msmtp-and-gmail/
<?
require("phpmailer/class.p
$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.co
$name="name"; // Recipient's name
$mail->From = $webmaster_email;
$mail->FromName = "Webmaster";
$mail->AddAddress($email,$
$mail->AddReplyTo($webmast
$mail->WordWrap = 50; // set word wrap
$mail->AddAttachment("/var
$mail->AddAttachment("/tmp
$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";
}
?>