【问题标题】:Send from free Gmail account via PHP [duplicate]通过 PHP 从免费的 Gmail 帐户发送 [重复]
【发布时间】:2013-04-07 23:37:02
【问题描述】:

我想使用我的免费 G​​mail 作为From 发件人,通过 PHP 脚本发送电子邮件。怎样才能使 SPF 记录有效(就好像邮件实际上是从 Gmail 发送的一样)?

【问题讨论】:

    标签: email php gmail dns dkim


    【解决方案1】:

    还有许多其他库。其中一些是:

    您可以使用这些库中的任何一个使用 SMTP 从 PHP 发送邮件

    使用带有 PHPMailer 库的 Gmail 帐户发送邮件的示例如下:

    //include the file
    require_once('class.phpmailer.php');
    
    $phpmailer          = new PHPMailer();
    
    
    $phpmailer->IsSMTP(); // telling the class to use SMTP
    $phpmailer->Host       = "ssl://smtp.gmail.com"; // SMTP server
    $phpmailer->SMTPAuth   = true;                  // enable SMTP authentication
    $phpmailer->Port       = 465;          // set the SMTP port for the GMAIL server; 465 for ssl and 587 for tls
    $phpmailer->Username   = "yourname@yourdomain"; // Gmail account username
    $phpmailer->Password   = "yourpassword";        // Gmail account password
    
    $phpmailer->SetFrom('name@yourdomain.com', 'First Last'); //set from name
    
    $phpmailer->Subject    = "Subject";
    $phpmailer->MsgHTML($body);
    
    $phpmailer->AddAddress($to, "To Name");
    
    if(!$phpmailer->Send()) {
      echo "Mailer Error: " . $phpmailer->ErrorInfo;
    } else {
      echo "Message sent!";
    }
    

    希望对你有帮助

    【讨论】:

      【解决方案2】:

      作为解决方案之一,可以使用 Zend Framework Zend_Mail class

          $email_conf = array(
              'auth' => 'login',
              'username' => 'your_login',
              'password' => 'your_password',
              'ssl' => 'tls',
              'port' => '587'
          );
          $transport = new Zend_Mail_Transport_Smtp('smtp.gmail.com', $email_conf);
          Zend_Mail::setDefaultTransport($transport);
      
          $mailer = new Zend_Mail('utf-8');
          $mail->addTo($recipientEmail); 
          $mail->setSubject($subject);
          $mailer->setBodyHtml($html);
          $mail->send();
      

      【讨论】:

        【解决方案3】:

        您必须通过 Google 的 SMTP 服务器发送邮件。如果您需要纯 PHP,请找到一个 SMTP 库(我只知道 PEAR 中的 Net_SMTP)并使用 Gmail 为您提供的常用设置将其配置为 smtp.gmail.com

        【讨论】:

          猜你喜欢
          • 2013-04-17
          • 2018-05-07
          • 1970-01-01
          • 2011-03-08
          • 2023-02-19
          • 1970-01-01
          • 1970-01-01
          • 2014-10-01
          • 1970-01-01
          相关资源
          最近更新 更多