2013-01-06 87 views
0

我的代碼簽約Gmail中使用PHP IMAP

$headers = 'MIME-Version: 1.0' . PHP_EOL; 
$headers .= 'Content-type: text/html; charset=iso-8859-1' . PHP_EOL; 
$headers .= 'From: Me <[email protected]>' . PHP_EOL; 
imap_mail('[email protected]','test',"$output","$headers"); 

有沒有簽署郵件的方式?當我用上面的代碼來測試發送電子郵件,我收到了電子郵件,但我得到的錯誤

This message may not have been sent by: [email protected] 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驗證電子郵件?

回答

1

如果您想以Gmail用戶身份發送郵件,我建議您使用Gmail的SMTP。由於IMAP主要用於從收件箱接收郵件。

以下是如何從Gmail的SMTP發送郵件的方法。

首先

  • 確保已安裝了PEAR郵件包。
    • 通常情況下,特別是與PHP 4或更高版本,這已經 已經爲你做了。試試吧。 (Mail.php)

然後

從PHP使用SMTP驗證發送郵件 - 實施例

<?php 
require_once "Mail.php"; 

$from = "Sender <[email protected]>"; 
$to = "Recipient <[email protected]>"; 
$subject = "Hi!"; 
$body = "Hi,\n\nHow are you?"; 

$host = "smtp.gmail.com"; 
$username = "[email protected]"; 
$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>"); 
    } 
?> 

從PHP使用SMTP認證和SSL加密發送郵件 - 實施例

<?php 
require_once "Mail.php"; 

$from = "Sender <[email protected]>"; 
$to = "Recipient <[email protected]>"; 
$subject = "Hi!"; 
$body = "Hi,\n\nHow are you?"; 

$host = "ssl://smtp.gmail.com"; 
$port = "465"; 
$username = "[email protected]"; 
$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

+1

只要注意,谷歌的SMTP服務,在某種程度上頭不與相關的RFP符合篡改:http://lee-phillips.org/gmailRewriting/ –