PHPMAILER 不工作但自动默认邮件功能 运行
PHPMAILER Not Working but Default mail function automatically running
/*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();
}
}
我在索引页面上使用了上面的这些代码,email.php 中的代码和 email.php 中的代码包含在 config.But 中,它不能代替默认的 mail() 函数 运行.....我尝试了所有的东西,甚至连 phpmailer 的最新代码都崩溃了..任何人都有想法所以请帮助
这是错误的:
$Mailer = 'isSMTP';
应该是:
$Mailer = 'SMTP';
更好的方法是从覆盖的构造函数中调用 $this->isSMTP()
。
如果您要像那样强制设置 AltBody
,我还建议您使用内置的 html2text
方法。
如果您要覆盖某些内容,请阅读代码。
这是一个改进版本:
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();
}
}
}
您发送哪封电子邮件
例如:gmail 或 hotmail
如果 ssl 不存在
hotmail 会自动删除电子邮件,甚至不通知。您已为特定发件人添加例外。
/*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();
}
}
我在索引页面上使用了上面的这些代码,email.php 中的代码和 email.php 中的代码包含在 config.But 中,它不能代替默认的 mail() 函数 运行.....我尝试了所有的东西,甚至连 phpmailer 的最新代码都崩溃了..任何人都有想法所以请帮助
这是错误的:
$Mailer = 'isSMTP';
应该是:
$Mailer = 'SMTP';
更好的方法是从覆盖的构造函数中调用 $this->isSMTP()
。
如果您要像那样强制设置 AltBody
,我还建议您使用内置的 html2text
方法。
如果您要覆盖某些内容,请阅读代码。
这是一个改进版本:
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();
}
}
}
您发送哪封电子邮件 例如:gmail 或 hotmail
如果 ssl 不存在 hotmail 会自动删除电子邮件,甚至不通知。您已为特定发件人添加例外。