使用gmail服务器发送电子邮件

时间:2011-03-03 05:48:20

标签: php smtp phpmailer

  

可能重复:
  Send email using GMail SMTP server from PHP page

您好

我想使用gmail服务器为我的php网站发送电子邮件。任何人都可以使用phpmailer帮助我完成此代码吗?

require("phpmailer/class.phpmailer.php");

$mail = new PHPMailer();    
$mail->IsSMTP(); // send via SMTP
IsSMTP(); // send via SMTP

$mail->SMTPAuth = true; // turn on SMTP authentication  
$mail->Username = "mail@domain.com"; // SMTP username
$mail->Password = "mailpass"; // SMTP password
$webmaster_email = "admin@frendzpark.com"; //Reply to this email ID
$email="sanksmr@gmail.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->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";
}

0 个答案:

没有答案