0

我是 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 &gt;&gt;
    <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);

提前致谢!

PS 我已经在网上阅读了关于 php.ini 文件夹的信息。我正在从头开始创建一个网站,但不知道这是什么或是否有必要。另外,我正在使用没有电子邮件地址的免费托管服务。我不确定这是否会影响它。

4

1 回答 1

0

编辑:正如评论指出的那样,您的代码没有$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');

按照您的主机提供商的说明修改域名、用户电子邮件和端口号。

于 2012-08-22T00:37:10.853 回答