2014-01-21 135 views
0

我是PHP,PHPMyAdmin,Localhost等新手。我目前正在建立一個網站,我正在測試我的本地主機(我已經在我的Ubuntu上安裝了Xampp)。我想創建一個註冊表單,它工作正常(一切都發送到我的數據庫),但是我想看看哪些用戶實際上已經激活了他們的帳戶。php註冊後發送驗證郵件

所以我想製作一個驗證郵件,其中包含一個唯一的代碼。現在的問題是我試圖輸入:mail($to, $subject, $message, $headers),但我發現它不起作用。

我試圖安裝sendmail,postfix,dovecot,telnet等,但似乎沒有任何工作,我找不到一個好的演練。

我使用以下工作:Ubuntu(12.04LTS),xampp(php5.5),localhost/phpmyadmin。

如果有人知道一個好的演練,或知道如何使這項工作,我真的很感激它!

+0

安裝postfix的教程https://help.ubuntu.com/community/Postfix –

+0

在cmd行輸入:「sendmail [email protected]」,嘗試發送郵件功能。然後你的消息,發送按ctrl + D,如果evrything設置好,schould發送郵件到[email protected] –

回答

0

您可以嘗試使用PHPMailer。這是一個用PHP發送電子郵件的強大庫。

https://github.com/Synchro/PHPMailer

在這裏,我會把一個例子給你。

首先,下載 PHPMailer爲您的計算機。
其次,安裝時需要安裝PHPMailerAutoload.php。在我的例子中,它在phpmailer目錄中。這一個(PHPMailer的)是在同一個目錄中我的應用程序,所以:

<?php 
require 'phpmailer/PHPMailerAutoload.php'; 

//Create a new PHPMailer instance 
$mail = new PHPMailer(); 
//Set who the message is to be sent from 
$mail->setFrom('[email protected]', 'First Last'); 
//Set an alternative reply-to address 
$mail->addReplyTo('[email protected]', 'First Last'); 
//Set who the message is to be sent to 
$mail->addAddress('[email protected]', 'John Doe'); 
//Set the subject line 
$mail->Subject = 'PHPMailer mail() test'; 
//Read an HTML message body from an external file, convert referenced images to embedded, 
//convert HTML into a basic plain-text alternative body 
$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__)); 
//Replace the plain text body with one created manually 
$mail->AltBody = 'This is a plain-text message body'; 
//Attach an image file 
$mail->addAttachment('images/phpmailer_mini.gif'); 

//send the message, check for errors 
if (!$mail->send()) { 
    echo "Mailer Error: " . $mail->ErrorInfo; 
} else { 
    echo "Message sent!"; 
} 
?> 

我從PHPMailer的GitHub的這個例子https://github.com/PHPMailer/PHPMailer/blob/master/examples/mail.phps

您也可以使用Gmail帳戶(如果有的話)發送電子郵件 https://github.com/PHPMailer/PHPMailer/blob/master/examples/gmail.phps

那裏還有其他的例子。

讓我們知道你是如何修復它的。 祝你好運。