简体   繁体   English

初学者PHP:Mail()函数不起作用

[英]Beginner PHP: Mail() Function not Working

I am new to php so please bear with me. 我是php新手,请耐心等待。 I have created a registration for a test website which I am creating. 我已经为要创建的测试网站创建了注册。 The website collects user information and then sends a confirmation email. 该网站收集用户信息,然后发送确认电子邮件。 So far, no email has arrived after several attempts. 到目前为止,经过几次尝试,仍未收到电子邮件。 I have tried the spam folder, yet to no avail. 我尝试了垃圾邮件文件夹,但无济于事。

Here is my code: 这是我的代码:

$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);

Thanks in advance! 提前致谢!

PS I have read online about a php.ini folder. PS:我已经在线阅读了有关php.ini文件夹的信息。 I am creating a website from scratch and do not know what this is or if its necessary. 我正在从头开始创建一个网站,不知道这是什么,或者它是否必要。 Also, I am using a free hosting service which does not have an email address. 另外,我正在使用没有电子邮件地址的免费托管服务。 I am not sure if this affects it. 我不确定这是否会影响它。

EDIT: As comments point out, your code doesn't define $to properly and has syntax errors. 编辑:正如注释所指出的那样,您的代码未正确定义$to且存在语法错误。


Make sure your SMTP server is configured correctly. 确保正确配置了SMTP服务器。 This is the server used to send (and receive but not applicable) emails and the location of it will probably be written somewhere in the help/FAQ section of your hosting service, if they supply one. 这是用于发送(和接收但不适用)电子邮件的服务器,并且电子邮件的位置可能会写在托管服务的“帮助/常见问题”部分中的某个位置(如果它们提供的话)。

The php.ini file is used to define environment variables for the PHP server, such as the location of the SMTP server. php.ini 文件用于定义PHP服务器的环境变量,例如SMTP服务器的位置。 These settings can also be configured from within PHP with 这些设置也可以在PHP中使用

 ini_set('SMTP', 'smtp.example.com'); ini_set('sendmail_from', 'user@example.com'); ini_set('smtp_port','25'); 

Modifying the domain name, user email and port number as described by your host provider. 按照主机提供商的说明修改域名,用户电子邮件和端口号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM