[英]PHP MAILER - EMAIL SENDING
我想向尝试注册的用户发送确认邮件。 我正在使用 PHP Mailer 发送邮件。 这是我的代码:
require_once("PHPMailer/class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "localhost";
$mail->SMTPAuth = true;// turn on SMTP authentication
$mail->Username = "root";// SMTP username
$mail->Password = "";// SMTP password
$mail->SetLanguage("en","PHPMailer/language");
//compose mail
$mail->From = "admin@localhost.com";
$mail->FromName = "Cinema Admin";
$mail->AddAddress($_POST['email']);
$mail->AddReplyTo("admin@localhost.com", "Cinema Admin");
$mail->Subject = 'Your confirmation link here';
$mail->Body = "Your confirmation link\r\n";
$mail->Body .= "Click on this link to activate your sccount\r\n";
$mail->Body .= "http://localhost/user.login_plugin/confirm.php?passkey=$confirm_code";
//send mail
if (!$mail->Send())
{
echo "Message was not sent <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message has been sent";
当我执行文件时,它说
Message was not sent
Mailer Error: SMTP connect() failed.
任何人都可以建议我从本地主机向注册用户的 emailid 发送邮件。 我在堆栈溢出中搜索了几个关于“结束电子邮件”的标题,但无法从任何帖子中找到任何解决方案。
先感谢您
您可以尝试删除 smtp 部分吗? 根据您的评论,您没有设置邮件服务器。
$mail = new PHPMailer();
$mail->SetLanguage("en","PHPMailer/language"); // remove smtp things
您必须需要 SMTP 详细信息才能使用 SMTP 发送电子邮件,例如,如果您想使用 gmail 设置 SMTP,
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "tls"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 587; // set the SMTP port for the GMAIL server
$mail->Username = "yourusername@gmail.com"; // GMAIL username
$mail->Password = "yourpassword"; // GMAIL password
如果您不想使用 SMTP,您可以调用默认邮件功能
$mail->IsMail(); //Sets Mailer to send message using PHP mail() function.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.