【问题标题】:signing gmail with php imap使用 php imap 签署 gmail
【发布时间】:2013-01-06 07:50:10
【问题描述】:

我的代码

$headers  = 'MIME-Version: 1.0' . PHP_EOL;
$headers .= 'Content-type: text/html; charset=iso-8859-1' . PHP_EOL;
$headers .= 'From: Me <me@gmail.com>' . PHP_EOL;
imap_mail('you@gmail.com','test',"$output","$headers");

有没有办法在邮件上签名?当我使用上面的代码测试发送电子邮件时,我收到了电子邮件但我收到了错误

This message may not have been sent by: me@gmail.com  Learn more  Report phishing

according to gmail 他们将签名数据附加到标头以进行身份​​验证

我正在使用 gmail imap 发送邮件

$inbox = imap_open($hostname,$username,$password)
          or die('Cannot connect to Gmail: ' . imap_last_error());

有没有办法使用 php imap 对电子邮件进行身份验证?

【问题讨论】:

    标签: php email imap


    【解决方案1】:

    如果您想以 Gmail 用户的身份发送邮件,我建议您使用 Gmail 的 SMTP。因为 IMAP 主要用于接收来自收件箱的邮件。

    以下是从 Gmail 的 SMTP 发送邮件的方法。

    第一

    • 确保已安装 PEAR Mail 包。
      • 通常,尤其是 PHP 4 或更高版本,这将已经 已经为你完成了。试一试。 (Mail.php)

    然后

    使用 SMTP 身份验证从 PHP 发送邮件 - 示例

    <?php
     require_once "Mail.php";
    
     $from = "Sender <sender@gmail.com>";
     $to = "Recipient <recipient@gmail.com>";
     $subject = "Hi!";
     $body = "Hi,\n\nHow are you?";
    
     $host = "smtp.gmail.com";
     $username = "username@gmail.com";
     $password = "Gmail Password";
    
     $headers = array ('From' => $from,
       'To' => $to,
       'Subject' => $subject);
     $smtp = Mail::factory('smtp',
       array ('host' => $host,
         'auth' => true,
         'username' => $username,
         'password' => $password));
    
     $mail = $smtp->send($to, $headers, $body);
    
     if (PEAR::isError($mail)) {
       echo("<p>" . $mail->getMessage() . "</p>");
      } else {
       echo("<p>Message successfully sent!</p>");
      }
     ?>
    

    使用 SMTP 身份验证和 SSL 加密从 PHP 发送邮件 - 示例

    <?php
     require_once "Mail.php";
    
     $from = "Sender <sender@gmail.com>";
     $to = "Recipient <recipient@gmail.com>";
     $subject = "Hi!";
     $body = "Hi,\n\nHow are you?";
    
     $host = "ssl://smtp.gmail.com";
     $port = "465";
     $username = "username@gmail.com";
     $password = "Gmail Password";
    
     $headers = array ('From' => $from,
       'To' => $to,
       'Subject' => $subject);
     $smtp = Mail::factory('smtp',
       array ('host' => $host,
         'port' => $port,
         'auth' => true,
         'username' => $username,
         'password' => $password));
    
     $mail = $smtp->send($to, $headers, $body);
    
     if (PEAR::isError($mail)) {
       echo("<p>" . $mail->getMessage() . "</p>");
      } else {
       echo("<p>Message successfully sent!</p>");
      }
     ?>
    

    来源about.com

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-02-06
    • 2013-12-22
    • 2013-04-07
    • 2010-12-26
    • 2015-11-20
    • 1970-01-01
    • 2016-09-01
    • 2023-03-19
    相关资源
    最近更新 更多