2014-09-18 35 views
0

我使用PHP的mail()函數從我的網站發送自動電子郵件,並在測試時發現,當我通過Gmail從網站發送郵件時,電子郵件由PHP郵件發送正在收件人端產生以下警告:此消息可能不會發送:[email protected]瞭解更多舉報網絡釣魚。但是,當我使用其他電子郵件(如雅虎,Outlook),然後我沒有收到我的$ contact_email電子郵件。請幫我解決這個問題。PHP的郵件()函數無法正常工作

**我不想使用Google應用。和我的域名電子郵件地址。 **我只是想要如果有人聯繫(填寫表格),然後我剛剛在我的網站上收到電子郵件。 下面的代碼:

<?php 
 
global $_REQUEST; 
 
$response = array('error'=>''); 
 

 
    $user_name = substr($_REQUEST['user_name'], 0, 20); 
 
    $user_email = substr($_REQUEST['user_email'], 0, 40); 
 
    $user_msg = $_REQUEST['user_msg']; 
 

 
    $contact_email = '[email protected]';  
 

 
    if (trim($contact_email)!='') { 
 
     $subj = 'Message from Official Website'; 
 
     $msg = "Name: $user_name 
 
     E-mail: $user_email 
 
     Message: $user_msg"; 
 

 
     $head = "Content-Type: text/plain; charset=\"utf-8\"\n" 
 
      . "X-Mailer: PHP/" . phpversion() . "\n" 
 
      . "Reply-To: $user_email\n" 
 
      . "To: $contact_email\n" 
 
      . "From: $user_email\n"; 
 

 
     if ([email protected]($contact_email, $subj, $msg, $head)) { 
 
      $response['error'] = 'Error send message!'; 
 
     } 
 
    } else 
 
      $response['error'] = 'Error send message!'; 
 

 
    echo json_encode($response); 
 
    die(); 
 

 
?>

+0

您發送的電子郵件地址不是官方Gmail地址。 Google隨後會標記您的電子郵件以模仿他們。雅虎/ Outlook可能會自動刪除電子郵件。 – Grice 2014-09-18 19:53:58

+0

如果它只是一個聯繫表單,難道你不能只使用提交給'mailto'的HTML表單嗎? – muttley91 2014-09-18 19:54:46

回答

0

周圍有沒有辦法和谷歌所做的只是防止SAPM。嘗試從'[email protected]'發送'reply-to'作爲您的gmail。你的域名應該是你發送的網站所在的域名。

另一方面,我還建議使用一個封裝郵件函數的庫,看看SwiftMailer。

+0

如何在'reply-to'中添加gmail?你能幫我寫這個嗎? – 2014-09-18 20:12:49