请记住,我是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);
我相信第二个代码片段会适合原来的某个地方,但是,我已经尝试了几个小时来解决这个问题无济于事。我感谢任何帮助,如果您需要查看实际的密码恢复表单代码或认为我可以改进我的问题,请告诉我。
答案 0 :(得分:1)
阻止您发送smtp电子邮件的原因有很多(假设您使用的是正确的SMTP库)
希望可以提供帮助。
答案 1 :(得分:0)
尝试使用PHPMailer。这个工具非常强大。您只需要将其包含在您的网站中,配置即可。此外,良好的文档和易于理解。