簡體   English   中英

如何通過我網站上的與我們聯系表格在我的免費gmail收件箱中獲取用戶郵件

[英]How to get user mails in my free gmail inbox through contact us form on my website

如何通過我網站上的“與我們聯系”表單在我的免費gmail收件箱中獲取用戶郵件。 我不使用帶有我的網站名稱的電子郵件。 我使用免費的Gmail。 我嘗試了許多腳本,但是所有人都需要域上的電子郵件帳戶。

請問這個問題有什么做這一個

好吧,所以您的網站上有一個表格,您的用戶填寫了表格,您需要一封包含該數據的電子郵件,對嗎?

簡單的例子:

<form action="sendMail.php" method="post">
    Name: <input type="text" name="name" id="name" /><br />
    Email: <input type="text" name="email" id="email" /><br />
    Text: <textarea name="text"></textarea><br />
    <input type="submit" value="Send" />
</form>

然后,php頁面發送郵件:

//php sendThis.php page
<?php
require("class.phpmailer.php");
$name = $_POST['name'];
$email = $_POST['email'];
$text = $name . ', ' . $email . ' has filled the form with the text:<br />' . $_POST['text'];

$from = 'your.email@gmail.com';
$to = 'your.email@gmail.com';
$gmailPass = 'your gmail password';

$mail = new PHPMailer();
$mail->IsSMTP();
// enable SMTP authentication
$mail->SMTPAuth = true;
// sets the prefix to the server
$mail->SMTPSecure = "ssl";
// sets GMAIL as the SMTP server
$mail->Host = 'smtp.gmail.com';
// set the SMTP port
$mail->Port = '465';
// GMAIL username
$mail->Username = $from;
// GMAIL password
$mail->Password = $gmailPass;
$mail->From = $from;
$mail->FromName = $from;
$mail->AddReplyTo($from, $from);
$mail->Subject = 'This is a test!';
$mail->Body = $text;
$mail->MsgHTML($text);
$mail->IsHTML(true);
$mail->AddAddress($to, $to);

if(!$mail->Send()){
    echo $mail->ErrorInfo;
}else{
    echo 'sent!';
    $mail->ClearAddresses();
    $mail->ClearAttachments();
}
?>

編輯:剛剛測試,並且工作正常。 確保3個文件(class.phpmailer.php,class.pop3.php和class.smtp.php)位於正確的包含路徑中

嘗試啟用openssl

取消注釋行:

extension=php_openssl.dll

在您的php.ini文件中。

基本上,它涉及PHP mail()函數:

<?php 
     mail(yourGmailAddress, object, message); 
?>

如您所見,此解決方案僅在Web服務器操作郵件服務器時才有效。 該郵件服務器可能禁止未知用戶。 因此,您需要在該Web /郵件服務器上擁有一個電子郵件帳戶(我相信是這種情況)。 然后,第二步是將郵件從您的網站地址轉發到您的Gmail帳戶。 我90%確信可以通過您的gmail配置進行操作。 也可以通過您的網站郵件配置。 但是不要同時配置兩者!

您也可以將您的電子郵件地址放入form元素的“ a​​ction”屬性中。 但這是非常不可靠的。 像這樣:

<form method='post' action='mailto:your@email.com?Subject=Hello'>
...
</form>

用戶必須安裝並配置了電子郵件客戶端才能正常工作。 還有其他一些缺點。 您必須進行一些研究才能找到此方法是否適合您。 http://www.google.com/search?client=opera&rls=en&q=form+action+mailto&sourceid=opera&ie=utf-8&oe=utf-8

暫無
暫無

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

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