1

これは私の最初の質問です。これを読んでくれてありがとう。登録とログインの部分で、PHP academy のチュートリアルに従っています。

私は Amazon の EC2 サービスを使用しており (これは今のところうまく機能しています)、コードを変更して (別の Web ホストから) SMTP サーバーを使用してアクティベーション メールを送信する方法を知りたいです。以下のコードを参照してください。ご不明な点がございましたら、お気軽にお問い合わせください。繰り返しますが、これは初めてです。

助けてくれてありがとう。

敬具、 エンリコ・ユースマン

General.php ファイル:

function email($to, $ubject, $body) {
mail($to, $subject, $body, 'From: activate@proxico.nl');}

Users.php ファイル:

function register_user($register_data) {

array_walk($register_data, 'array_sanitize');
        $register_data['password'] = md5($register_data['password']);

        $fields = '`' . implode('`, `', array_keys($register_data)) . '`';
        $data = '\'' . implode('\', \'', $register_data) . '\'';

        mysql_query("INSERT INTO `users` ($fields) VALUES ($data)");
        email($register_data['email'], 'Activate your account',"Hello " . $register_data['first_name'] . ",\n\nYou need to activate your account, so use the link below:\n\nhttp://ec2-54-229-189-136.eu-west-1.compute.amazonaws.com/activate.php?email=" . $register_data['email'] . "&email_code=" . $register_data['email_code'] . " \n\n - Proxico");

}

Register.php ファイル:

if (isset($_GET['success']) && empty($_GET['success'])) {
    echo 'You\'ve been registered successfully! Please check your email for an activation link. Didn\'t get an email? Click here to resend.';
} else {
    if (empty($_POST) === false && empty($errors) === true) {
    $register_data = array(
        'username'      => $_POST['username'],
        'password'      => $_POST['password'],
        'first_name'    => $_POST['first_name'],
        'last_name'     => $_POST['last_name'],
        'email'         => $_POST['email'],
        'email_code'    => md5($_POST['username'] + microtime())
    );

    register_user($register_data);
    header('Location: register.php?success');
    exit();


} else if (empty($errors) === false) {
    echo output_errors($errors);
    // output register errors
}
4

3 に答える 3

1

PHPMailer クラスを使用して、コードで SMTP サーバーを簡単に指定します。それ以外の場合は、php.ini ファイルを変更するだけです。

https://code.google.com/a/apache-extras.org/p/phpmailer/

于 2013-10-09T17:16:38.623 に答える