PHP Mailer:我应该把PHP Mailer的脚本放在哪里?

时间:2017-05-05 19:09:53

标签: php forms macos xampp phpmailer

我不知道在哪里将 PHPMailer 脚本放在我的代码上?在我的代码中,我应该修改哪些内容?我是OOP的初学者......我感谢您提供的任何帮助。谢谢 !

<?php

require 'PHPMailerAutoload.php';

$mail = new PHPMailer;

//$mail->SMTPDebug = 3;                               // Enable verbose debug output

$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'smtp1.example.com;smtp2.example.com';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'user@example.com';                 // SMTP username
$mail->Password = 'secret';                           // SMTP password
$mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587;                                    // TCP port to connect to

$mail->setFrom('from@example.com', 'Mailer');
$mail->addAddress('joe@example.net', 'Joe User');     // Add a recipient
$mail->addAddress('ellen@example.com');               // Name is optional
$mail->addReplyTo('info@example.com', 'Information');
$mail->addCC('cc@example.com');
$mail->addBCC('bcc@example.com');

$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
$mail->isHTML(true);                                  // Set email format to HTML

$mail->Subject = 'Here is the subject';
$mail->Body    = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';

}





// This my Code 


<?php 

require('includes/functions.php'); 
require('config/database.php'); 
require('includes/constants.php'); 


$pseudo = ""; 


if(isset($_POST['register'])){ 



    if(not_empty(['name', 'pseudo','email','password','password_confirm'])){


    }


   $errors = []; 

    extract($_POST);

    if(mb_strlen($pseudo) < 3) { 

        $errors[] = "username too short ! (Minimum 3 caractere )"; 

    }

    if(!filter_var($email, FILTER_VALIDATE_EMAIL)){ 


        $errors[] = "Adresse email invalid";

    }

    if(mb_strlen($password) < 6 ){

        $errors[] = "password too short !(Minimum 6 caracteres)"; 

    }

    else { 

        if($password != $password_confirm){ 

            $errors[] = "  !"; 




        }



    }

    if(is_already_in_use('pseudo' , $pseudo, 'users')){ 

        $errors[] ="username already used!"; 



    }

    if(is_already_in_use('email' , $email, 'users')){ 

        $errors[] ="email adress already use!"; 

}

if(count($errors) == 0) { 

    //Envoi E-mail d'activation

    $to = $email; 

    $subject = WEBSITE_NAME. " - ACCOUNT ACTIVATE "; 
    $token = sha1($pseudo.$email.$password); 

    ob_start(); 
    require('templates/emails/activation.tmpl.php'); 
    $content = ob_get_clean(); 

    $headers = 'MIME-Version:1.0' . "\r\n"; 
    $headers .='Content-type: text/html; charset=iso-8859-1' ."\r\n"; 

    mail($to, $subject, $content, $headers); 



    echo "E-mail Activation account confirm sent!";




}

else {

    $errors = "Please fill the area!"; 


}

}




 ?>

<?php require("views/register.view.php"); ?> 

0 个答案:

没有答案