0

I tried sending email using smtp gmail using phpmailer. My gmail account got suspended saying that there is an unusual activity. Here is the code I have used for sending emails. What's the correct way of sending emails using smtp gmail in phpmailer?

My question is not duplicate. I have already tried this : Send email using the GMail SMTP server from a PHP page

I'm using phpmailer, and my accounts getting suspended.

<?php
include('phpmailer.php');
class Mail extends PhpMailer
{
      // Set default variables for all new objects
    public $From     = 'noreply@exmaple.org';
    public $FromName = SITETITLE;
    public $Host     = 'smtp.gmail.com';
    public $Mailer   = 'smtp';
    public $SMTPAuth = true;
    public $Username = 'username@gmail.com';
    public $Password = 'password';
    public $SMTPSecure = 'tls';
    public $WordWrap = 75;

    public function subject($subject)
    {
        $this->Subject = $subject;
    }

    public function body($body)
    {
        $this->Body = $body;
    }

    public function send()
    {
        $this->AltBody = strip_tags(stripslashes($this->Body))."\n\n";
        $this->AltBody = str_replace("&nbsp;", "\n\n", $this->AltBody);
        return parent::send();
    }
}

Here is my php code :

$to = $_POST['email'];
            $subject = "Registration Confirmation";
            $body = "<p>Thank you for registering at demo site.</p>
            <p>To activate your account, please click on this link: <a href='".DIR."activate.php?x=$id&y=$activasion'>".DIR."activate.php?x=$id&y=$activasion</a></p>
            <p>Regards Site Admin</p>";

            $mail = new Mail();
            $mail->setFrom('noreply@example.org');
            $mail->addAddress($to);
            $mail->subject($subject);
            $mail->body($body);
            $mail->send();

            //redirect to index page
            header('Location: index.php?action=joined');
            exit;
Community
  • 1
  • 1
Arun
  • 39
  • 6

0 Answers0