2014-01-21 132 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

那里还有其他的例子。

让我们知道你是如何修复它的。 祝你好运。