我有一個關於在PHP發送電子郵件的一些問題。過去幾天我一直在谷歌,我仍然無法完成這項工作。PHP發送電子郵件的問題
我的第一個問題是,我該如何改變「從」我的電子郵件的部分?在我的「從」部分:我有「[email protected]要」:
我想剛纔我的域名(如適當的名稱:「testingstuff.com」 - > 「測試材料」)。我怎麼能做到這一點?
有一次,我居然打開電子郵件一切都在它是好的,正確的,包括從電子郵件地址爲「[email protected]」。
而且我的郵件不會發送到Gmail的電子郵件地址。它顯示在我的郵件隊列中,我的日誌說它已發送,但從未在我的Gmail上收到。我是否需要採取額外步驟讓Google接受我的電子郵件?如果是的話那是什麼?其他主要郵件提供是否需要相同的步驟,或者它們是不同的步驟?
這是我到目前爲止的代碼:
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
ini_set("sendmail_from", "[email protected]");
class email {
public static function send($to, $subject, $message) {
$headers = "From: Testing Stuff <[email protected]>\r\n";
$headers .= "Reply-To: [email protected]\r\n";
$headers .= "Content-type: text/html\r\n";
mail($to, $subject, $message, $headers);
}
}
?>
用法:
require_once("../mail.php");
email::send("[email protected]", "testing email subject", "testing email body");
難道我做錯了什麼在我的代碼?
你檢查Gmail收件箱中的spamfolder?還有'$ headers。='From:My Domain <[email protected]>'。 「\ r \ n」;'應該工作的 – Evochrome
可能的複製[PHP郵件()的形式發送到Gmail的垃圾郵件(http://stackoverflow.com/questions/12188334/php-mail-form-sending-to-gmail-垃圾郵件)http://stackoverflow.com/questions/712392/send-email-using-the-gmail-smtp-server-from-a-php-page – zod
我會建議使用現有的電子郵件庫,像PHPMailer的,斯威夫特梅勒或類似的,並通過您的電子郵件提供商SMTP服務器發送電子郵件。這可能會解決兩個問題。 –