0
<?php
include('phpmailer.php');
class Mail extends PhpMailer
{
    // Set default variables for all new objects
    public $From     = 'my_email_id@gmail.com';
    public $FromName = SITETITLE;
    public $Host     = 'smtp.gmail.com';
    public $Mailer   = 'smtp';
    public $SMTPAuth = true;
    public $Username = 'my_enail_id@gmail.com';
    public $Password = 'mypass';
    public $SMTPSecure = 'ssl';
    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();
}

}

This is my code. phpmailer.php is this code

I am a newbie to php.

this is how I am invoking send() method.

        $mail = new Mail();
        $mail->setFrom(SITEEMAIL);
        $mail->addAddress($to);
        $mail->subject($subject);
        $mail->body($body);

        if(!$mail->send())
        {
           echo 'There was an error sending the message';
           exit;
        }
PHP Enthu
  • 105
  • 1
  • 2
  • 8

1 Answers1

0

You can t send email from localhost without installing sendmail plugin and configure it if you use wamp on Windows If you you use an other PHP server or operating system specify it

Haithem DISSEM
  • 74
  • 3
  • 12
  • I am running it on https://c9.io/ – PHP Enthu Jul 20 '17 at 06:32
  • Sending email directly from our servers using the SMTP port is blocked, otherwise spammers would use it to send out spam. Here are a couple things to note: If you're like to send email from within Cloud9, you can use Google Compute Engine partner services, like SendGrid, Mandrill, or Google Apps … Take a look here : https://community.c9.io/t/how-can-i-send-email-from-my-app/1262 – Haithem DISSEM Jul 20 '17 at 09:36