PHP邮件表单问题

时间:2013-12-25 01:58:25

标签: php mysql email

基本上我让我的PHP发送电子邮件给注册的人,然后他们的电子邮件将被验证。我做了一个测试运行,链接是用我的数据库生成的,它只是没有进入收件箱的电子邮件。我不确定它是否是延迟或代码的问题,但任何帮助将不胜感激。

要发送电子邮件的PHP:

<?php

include('config.php');

// table name 
$tbl_name=temp_members_db;

// Random confirmation code 
$confirm_code=sha1(uniqid(rand())); 

// values sent from form 
$name=$_POST['name'];
$email=$_POST['email'];

// Insert data into database 
$sql="INSERT INTO $tbl_name(confirm_code, name, email, password)VALUES('$confirm_code', '$name', '$email', '$password')";
$result=mysql_query($sql);

// if suceesfully inserted data into database, send confirmation link to email 
if($result){
// ---------------- SEND MAIL FORM ----------------

// send e-mail to ...
$to=$email;

// Your subject
$subject="Your confirmation link here";

// From
$header="from: Colourity <your email>";

// Your message
$message="Your Comfirmation link \r\n";
$message.="Click on this link to activate your account \r\n";
$message.="http://www.colourity.com/confirmation.php?passkey=$confirm_code";

// send email
$sentmail = mail($to,$subject,$message,$header);
}

// if not found 
else {
echo "Not found your email in our database";
}

// if your email succesfully sent
if($sentmail){
echo "Your Confirmation link Has Been Sent To Your Email Address.";
}
else {
echo "Cannot send Confirmation link to your e-mail address";
}
?>

3 个答案:

答案 0 :(得分:0)

您可以使用像HTML Mime Mail(RMail)这样的PHP类来充当SMTP客户端来发送您的电子邮件。您需要使用有效的电子邮件帐户,并且您的Web服务器仍然需要能够将数据发送到您的电子邮件帐户所需的任何端口(通常是端口25,465或587)。

答案 1 :(得分:0)

我会推荐SwiftMailer。关于使用SMTP连接到另一个帐户进行邮寄的说明是located here

require_once 'lib/swift_required.php';

// Create the Transport
$transport = Swift_SmtpTransport::newInstance('smtp.example.org', 25)
  ->setUsername('your username')
  ->setPassword('your password')
  ;

/*
You could alternatively use a different transport such as Sendmail or Mail:

// Sendmail
$transport = Swift_SendmailTransport::newInstance('/usr/sbin/sendmail -bs');

// Mail
$transport = Swift_MailTransport::newInstance();
*/

// Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);

// Create a message
$message = Swift_Message::newInstance('Wonderful Subject')
  ->setFrom(array('john@doe.com' => 'John Doe'))
  ->setTo(array('receiver@domain.org', 'other@domain.org' => 'A name'))
  ->setBody('Here is the message itself')
  ;

// Send the message
$result = $mailer->send($message);

但是所有这一切,我会调查您的主机是否可以处理localhost邮件,因为如果您有可用的话,这是最容易使用的。

答案 2 :(得分:0)

我会推荐PHPmailer Library。非常容易使用。

https://github.com/Synchro/PHPMailer