/*send email Using at Index.php page*/
$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>";
//include 'classes/phpmailer/mail.php';
//function Send_Mail($to,$subject,$body)
$mail = new Mail();
//$mail->setFrom(SITEEMAIL);
//$mail->Debugoutput = 'html';
$mail->addAddress($to);
//$mail->setFrom('noreply@domain.com', 'noreply');
//$mail->addReplyTo('replyto@example.com', 'First Last');
$mail->subject($subject);
//$mail->IsHTML(true);
$mail->body($body);
$mail->send();
/*PHP Mailer Code used in mail.php*/
<?php
include('class.phpmailer.php');
class Mail extends PhpMailer
//function Send_Mail($subject,$body)
{
// Set default variables for all new objects
public $From = 'rssbmonthlyreport@gmail.com';
public $FromName = SITETITLE;
public $Host = 'smtp.gmail.com';
public $Mailer = 'isSMTP';
public $SMTPAuth = true;
public $Username = 'abc@gmail.com';
public $Password = 'password';
public $SMTPSecure = 'tls';
public $Port = 587;
public $Priority = 1; // Highest priority - Email priority (1 = High, 3 = Normal, 5 = low)
public $CharSet = 'UTF-8';
public $Encoding = '8bit';
public $ContentType = 'text/html; charset=utf-8\r\n';
//public $From = 'rssbmonthlyreport@gmail.com';
//public $FromName = 'GMail Test';
public $WordWrap = 75;
public function subject($subject)
{
return $this->Subject = $subject;
}
public function body($body)
{
return $this->Body = $body;
}
public function send()
{
$this->AltBody = strip_tags(stripslashes($this->Body))."\n\n";
$this->AltBody = str_replace(" ", "\n\n", $this->AltBody);
return parent::send();
}
}
I am Using these code above at Index page and this in email.php and email.php was included in config.But it is not working in place of this default mail() function running.....I tried every thing even the latest code of phpmailer its crashing..Anyone has idea so please help
This is wrong:
$Mailer = 'isSMTP';
It should be:
$Mailer = 'SMTP';
A better approach would be to call $this->isSMTP()
from an overridden constructor.
I'd also recommend using the built-in html2text
method if you're going to forcibly set AltBody
like that.
If you're going to override things, read the code .
Here's an improved version:
class Mail extends PhpMailer
//function Send_Mail($subject,$body)
{
// Set default variables for all new objects
public $From = 'rssbmonthlyreport@gmail.com';
public $FromName = SITETITLE;
public $Host = 'smtp.gmail.com';
public $SMTPAuth = true;
public $Username = 'abc@gmail.com';
public $Password = 'password';
public $SMTPSecure = 'tls';
public $Port = 587;
public $Priority = 1; // Highest priority - Email priority (1 = High, 3 = Normal, 5 = low)
public $CharSet = 'UTF-8';
public $Encoding = '8bit';
//public $From = 'rssbmonthlyreport@gmail.com';
//public $FromName = 'GMail Test';
public $WordWrap = 75;
public function __construct($exceptions = null)
{
parent::__construct($exceptions);
$this->isSMTP();
$this->isHTML();
}
public function subject($subject)
{
return $this->Subject = $subject;
}
public function body($body)
{
return $this->Body = $body;
}
public function send()
{
$this->AltBody = $this->html2text($this->Body);
return parent::send();
}
}
}
which email you send ex: gmail or hotmail
if ssl not present hotmail automatically deletes email without even notifying. You have add exception for particular sender.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.