我是php的新手,所以请耐心等待。我已经为我正在创建的测试网站创建了注册。该网站收集用户信息,然后发送一封确认电子邮件。到目前为止,经过多次尝试,还没有收到任何电子邮件。我试过垃圾邮件文件夹,但没有用。
这是我的代码:
$to = "$email";
// Change this to your site admin email
$from = "someperson@gmail.com";
$subject = "Complete your registration";
//Begin HTML Email Message where you need to change the activation URL inside
$message = '<html>
<body bgcolor="#FFFFFF">
Hi ' . $username . ',
<br /><br />
You must complete this step to activate your account with us.
<br /><br />
Please click here to activate now >>
<a href="http://testw.freevar.com/activation.php?id=' . $id . '">
ACTIVATE NOW</a>
<br /><br />
Your Login Data is as follows:
<br /><br />
E-mail Address: ' . $email . ' <br />
Password: ' . $password . '
<br /><br />
Thanks!
</body>
</html>';
// end of message
$headers = "From: $from'r'n";
$headers .= "Content-type: text/html'r'n";
$to = "$to";
// Finally send the activation email to the member
mail($to, $subject, $message, $headers,-f $from);
提前感谢!
附言:我在网上读过一个php.ini文件夹。我正在从头开始创建一个网站,不知道这是什么,也不知道是否有必要。此外,我正在使用一个没有电子邮件地址的免费托管服务。我不确定这是否会影响它。
EDIT:正如注释所指出的,您的代码没有正确定义$to
,并且存在语法错误
请确保SMTP服务器配置正确。这是用于发送(和接收但不适用)电子邮件的服务器,如果他们提供,它的位置可能会写在托管服务的帮助/常见问题部分的某个地方
php.ini文件用于定义php服务器的环境变量,例如SMTP服务器的位置。这些设置也可以在带有的PHP中进行配置
ini_set('SMTP', 'smtp.example.com');
ini_set('sendmail_from', 'user@example.com');
ini_set('smtp_port','25');
按照主机提供商的说明修改域名、用户电子邮件和端口号。