简体   繁体   English

如何在我的网站上使用Google服务器发送电子邮件

[英]How to send email using google server in my site

Now we are using our own server to send email to our customers. 现在,我们正在使用自己的服务器向客户发送电子邮件。 its possible to send email using google server. 可以使用Google服务器发送电子邮件。 how to do this. 这个怎么做。 explain with php codes 用PHP代码解释

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) http://phpmailer.sourceforge.net下载PHPMailer提取到文件夹phpmailer创建文件email.php粘贴此代码并根据需要将其更改为蓝色(我修改了PHPMailer主页上给出的示例代码)

<?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";
    }
    ?>
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" 下载http://phpmailer.sourceforge.net/并将其命名为“ class.phpmailer.php”

http://micrub.info/2008/09/22/sending-email-with-zend_mail-using-gmail-smtp-services/ http://stackoverflow.com/questions/36079/php-mail-using-gmail

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 电子邮件未发送到我的服务器中 - Email is not send in my server HTML表单,用于在提交时使用php发送电子邮件(Google Cloud Server) - HTML form to send email using php on submit (Google Cloud Server) 如何使用本地安装的我自己的电子邮件服务器发送电子邮件 - How to send emails with my own email server installed locally 为什么我的网站发送的电子邮件使用codeigniter phpmailer在google和hotmail中被标记为垃圾邮件 - Why my email sent by my site is marked as spam in google and hotmail using codeigniter phpmailer 使用cpanel从我的实际网站(域名电子邮件地址)发送验证邮件 - send verification mail form my live site (domain email address) using cpanel 服务器A上的站点,希望从服务器B发送电子邮件 - site on server A, want to send its email from server B 使用域服务器 email 和 PHP 发送 email - Send email using domain server email with PHP 如何在谷歌应用程序引擎中使用PHP发送html格式的电子邮件 - How to send html format email using php in google application engine 如何在带有cURL的php中使用google gmail api发送电子邮件? - How to send an email, using google gmail api in php with cURL? 如何使用Google OAuth(通过SMTP)发送电子邮件? - How to send email using Google OAuth (via SMTP)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM