Jump to content

How can ı send custom e-mail from an hook ?


SametALMDR

Recommended Posts

Dear All,

I tried to send a custom email using PHPMailer but it doesnt work.I run the following codes and the information name surname etc. comes from an form which is in index page.

add_hook('ClientAreaPage', 1, function($vars) {
$mail = new PHPMailer(true);

if(isset($_POST['contact_ex'])){
    try {
        //Server settings
        $mail->isSMTP();                                            
        $mail->Host       = 'smtp.gmail.com';                    
        $mail->SMTPAuth   = true;                                   
        $mail->Username   = '---';                     
        $mail->Password   = '---';                              
        $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;         
        $mail->Port       = 587;
        $mail->CharSet  = 'utf-8';
    
        //Recipients
        $mail->setFrom($_POST['email'], $_POST['namesurname']);
        $mail->addAddress('example@hotmail.com', '--');     
        $mail->addReplyTo($_POST['email'], $_POST['namesurname']);
    
        // Content
        $mail->isHTML(true);                                  
        $mail->Subject = 'Subject';
        $mail->Body    = 'Some message';
    
        if($mail->send()){
            $res = '<div class="alert alert-success" role="alert">
                       <h5 class="alert-heading">Well done!</h5>
                       <p class="mb-0">Your contact information has been sended successfully!</p>
                    </div>';
        }else{
            $res = '<div class="alert alert-danger" role="alert">
                       <h5 class="alert-heading">Oops!</h5>
                       <p class="mb-0">Something went wrong.Please contact with us with phone!</p>
                    </div>';
        }
    } catch (Exception $e) {
            $res = '<div class="alert alert-danger" role="alert">
                       <h5 class="alert-heading">Oops!</h5>
                       <p class="mb-0">Something went wrong.Please contact with us with phone!</p>
                    </div>';
    }
}
});

It gives an error about class is not found how can ı create a PHPMailer object.Can you help me @brian! and all of guys ?

Edited by SametALMDR
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated