簡體   English   中英

PHP電子郵件文本到Gmail帳戶

[英]PHP email text to gmail account

有什么方法可以獲取文本(從表單中檢索)並將其通過電子郵件發送到我的Gmail帳戶? 我也可以讓用戶輸入其電子郵件地址和主題。 還是如果沒有更好的方法讓用戶向我發送消息? 謝謝。

使用mail功能將電子郵件發送到特定地址:

$subject = $_REQUEST['subject'];
$message = $_REQUEST['message'];
mail("your@gmail.com", $subject, $message); 

但是請不要從表單中獲取$to參數,否則您的腳本將被用作垃圾郵件。

我建議您使用PHP Mailer,該程序將處理所有消息構造,並與Gmail配合使用。 Gmail還提供了示例代碼。

擴展Ivan撰寫的內容,以向用戶添加電子郵件作為發件人:

$subject = $_POST['subject'];
$message = $_POST['message'];
$from    = $_POST['from'];

// the sender email must be cleaned of mime header injection
$from = preg_replace_all("/[\r\n]+/", '', $from);

mail("your@gmail.com", $subject, $message, "from:$from\n");

這使回復變得更容易。 但是,您可以在郵件正文中附加他們的電子郵件地址。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM