HTML邮件我想我做错了什么


The HTML Mail i think i did something wrong

我认为代码中有错误,我不知道它是什么,但 Web 服务器上的 mail() 肯定在工作。

该 HTML 邮件包含

$to = $register_data['email'];
$subject = 'Activate Your Account';
$headers = "non-reply@bruhkunt.herobo.com'r'n";
$headers .= "CC: bruhkunt.herobo.com'r'n";
$headers .= "MIME-Version: 1.0 'r'n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1'r'n";
$body = '<html><body>';
$body .= "<h1>Hello, " . $register_data['first_name'] . "</h1>'r'n";
$body .= "<p>To activate your account click the link below:</p>'r'n";
$body .= "<a href='"http://bruhkunt.herobo.com/activate.php?email=" . $register_data['email'] . "&email_code=" .$register_data['email_code']."'"></a>'r'n";
$body .= "<p>If it does not work, copy and paste the link below:</p>'r'n";
$body .= "http://bruhkunt.herobo.com/activate.php?email=" . $register_data['email'] . "&email_code=" .$register_data['email_code']."'r'n";
$body .= '</body></html>';

邮件功能:

function email($to, $subject, $body, $headers) {
        mail($to, $subject, $body, $headers);
}

这是发送主要的东西:

function register_user($register_data) {
    array_walk($register_data, 'array_sanitize');
    $register_data['password'] = crypt($register_data['password'], 'st');
    $field = '`' . implode('`, `', array_keys($register_data)) . '`';
    $data = '''' . implode(''', ''', $register_data) . '''';
    mysql_query("INSERT INTO `users` ($field) VALUES ($data)");
    email(include('core/activation_mail.php'));
}

您的函数email()具有您指定的必填字段。

function email($to, $subject, $body, $headers)
                ^      ^        ^        ^

如果您不提供它们(在您的示例中没有提供),它将无法正常运行并引发错误。你想做这样的事情:

$body = file_get_contents(getcwd(). 'core/activation_mail.php');
email('tosomeone@somewhere.com', 'The Subject', $body, $headers);

注意

我刚刚注意到您的"HTML电子邮件"页面,您不应该这样做,因为您现在必须尝试使用global。如果您这样做,它可能会起作用:

include('core/activation_mail.php');
email($to, $subject, $body, $headers);

为了帮助自己,请正确阅读 php。你正在做的事情是多余的,不是最有效的方法。

正如@Fred提到的,请始终阅读并了解您的PHP错误!在脚本顶部使用此代码打开错误报告!

ini_set('display_errors', 1);
error_reporting(E_ALL);