我正在网站上的注册页面上工作,我需要实施电子邮件验证。
我在服务器上安装了PHPMailer-master。代码的第一部分直接写在注册php:
include('send_mail.php');
$to=$email;
$subject="Email verification";
$body='Hi, <br/> <br/> thank you for joining us! Please verify your email and get started using your account. <br/> <br/> <a href="'.$base_url.'activation/'.$activation.'">'.$base_url.'activation/'.$activation.'</a>';
Send_Mail($to,$subject,$body);
$msg= "Registration successful, a verification email has ben sent to you. Please activate this to get started.";
send_mail.php中的代码:
<?php
function Send_Mail($to,$subject,$body)
{
require 'PHPMailer-master/class.phpmailer.php';
require 'PHPMailer-master/PHPMailerAutoload.php';
$from = "*mywebsite*";
$mail = new PHPMailer();
$mail->IsSMTP(true); // use SMTP
$mail->IsHTML(true);
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Host = "*my webhost's mailserver*"; // SMTP host
$mail->Port = 465; // set the SMTP port
$mail->Username = "*username*"; // SMTP username
$mail->Password = "*password*"; // SMTP password
$mail->SetFrom($from, '*mywebsite?*');
$mail->AddReplyTo($from,'*mywebsite?*');
$mail->Subject = $subject;
$mail->MsgHTML($body);
$address = $to;
$mail->AddAddress($address, $to);
$mail->Send();
}
?>
我非常确定send_mail.php中的信息是正确的。我在cPanel上使用我在配置邮件客户端页面上找到的信息(&#34;安全SSL / TLS设置&#34;)。
当我尝试注册时,网站会以某种方式变白。该帐户在phpmyadmin上创建。没有错误记录在public_html中。
有什么想法吗?
更新:抱歉迟到了回复。
我尝试过使用PHPMailer测试页面。当我尝试SMTP时,页面将永远加载。使用Sendmail时,我收到错误&#34;无法执行:/ usr / sbin / sendmail -t -i&#34;。当我使用QMAIL时,它说电子邮件已发送但我从未收到过。
但是......当我使用Mail时,我成功收到了它。是&#34; Mail&#34;足够安全使用?有什么区别?我应该如何将其实现到注册页面的php代码中?我无法在PHP邮件测试页代码中找到&#34; mail&#34;的任何特定部分。功能
代码现在看起来像这样:
$email = $_POST['email'];
require 'PHPMailer-master/PHPMailerAutoload.php';
$mail = new PHPMailer(true);
try {
$mail->AddReplyTo('myemail');
$mail->AddAddress($email);
$mail->SetFrom('myemail');
$mail->AddReplyTo('myemail');
$mail->Subject = 'subject';
$mail->Message = 'message comes here';
$mail->Send();
echo "Message Sent OK<p></p>\n";
} catch (phpmailerException $e) {
echo $e->errorMessage();
} catch (Exception $e) {
echo $e->getMessage();
}
错误消息:&#34;消息正文为空&#34;