用php imap签名gmail [英] signing gmail with php imap
问题描述
我的代码
$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");
有没有办法签署邮件?当我使用上面的代码来测试发送电子邮件时,我收到电子邮件,但是我收到错误
Is there a way to sign the mail? when I use above code to test sending emails, I receive the email but I am getting the error
This message may not have been sent by: me@gmail.com Learn more Report phishing
根据gmail ,他们将签名数据附加到标头进行身份验证
according to gmail they attach signed data to the headers to authenticate
我使用gmail imap发送邮件
I am using gmail imap to send the mails
$inbox = imap_open($hostname,$username,$password)
or die('Cannot connect to Gmail: ' . imap_last_error());
有没有办法使用php imap验证电子邮件?
Is there a way to authenticate the email using php imap?
推荐答案
如果您想以Gmail用户身份发送邮件,建议您使用Gmail的SMTP。由于IMAP主要用于从收件箱接收邮件。
If you want to send mails as a Gmail user I recommend using the Gmail's SMTP. As IMAP is mainly used to receive mails from the inbox.
以下是从Gmail的SMTP发送邮件的方法。
Here's how to send mails from Gmail's 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发送邮件 - 例如 p>
Sending Mail from PHP Using SMTP Authentication and SSL Encryption - Example
<?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>"); } ?>
这篇关于用php imap签名gmail的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
- 通常,特别是使用PHP 4或更高版本,这已经为您完成了