【发布时间】:2018-03-31 07:49:32
【问题描述】:
请记住,我是 PHP 新手
您好,我无法从仅使用 sendmail 的脚本发送 SMTP 邮件。
下面的代码是我原来的旧代码,但在查看时会在 Gmail 上发出警告。它说此消息无法验证。我正在尝试通过密码重置表单向用户发送他们的凭据(我也将在注册表单上实现这一点)。
原代码:
##### Mail functions #####
function sendLostPasswordEmail($myusername, $email, $newpassword)
{
global $domain;
$message = "
You have requested a new password on example.com
Here is Your new password information:
username: $myusername
password: $newpassword
Regards,
example Administration
";
if (sendMail($email, "Your password has been reset.", $message, "noreply@example.com"))
{
return true;
} else
{
return false;
}
}
function sendMail($to, $subject, $message, $from)
{
$from_header = "From: $from";
if (mail($to, $subject, $message, $from_header))
{
return true;
} else
{
return false;
}
return false;
}
function sendActivationEmail($myusername, $password, $uid, $email, $actcode)
{
global $domain;
$link = "https://example.com/includes/activate.php?uid=$uid&actcode=$actcode";
$message = "
Thank you for registering on https://example.com,
Your account information:
username: $myusername
password: $password
Please click the link below to activate your account.
$link
Regards
$domain Administration
";
if (sendMail($email, "Please activate your account.", $message, "noreply@example.com"))
{
return true;
} else
{
return false;
}
}
?>
要实现的代码(我认为)
require_once "php/Mail/mail.php";
$from = "Example Company <noreply@example.com>";
$to = "<>";
$subject = "Your Password Has Been Reset";
$body = "$message";
$host = "mail.example.com";
$port = "465";
$username = "noreply@example.com";
$password = "***";
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'port' => $port,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($to, $headers, $body);
我相信第二个代码 sn-p 会在某个地方与原始代码相匹配,但是,我已经尝试了几个小时来解决这个问题,但无济于事。感谢您的帮助,如果您需要查看实际的密码恢复表单代码或认为我可以改进我的问题,请告诉我。
【问题讨论】: