У меня возникают проблемы с отправкой писем с использованием класса PHPMailer для моей регистрационной формы. Мне было интересно, можно ли изменить код ниже обычного класса Mail.Как изменить класс PHPMailer на обычный Mail
<?php
require_once('PHPMailer_v5.1/PHPMailer.php');
class Email {
\t public $objUrl;
\t private $objMailer;
\t public function __construct($objUrl = null) {
\t
\t \t $this->objUrl = is_object($objUrl) ? $objUrl : new Url();
\t \t
\t \t $this->objMailer = new PHPMailer();
\t \t $this->objMailer->IsSMTP();
\t \t $this->objMailer->SMTPAuth = true;
\t \t $this->objMailer->SMTPKeepAlive = true;
\t \t $this->objMailer->SMTPSecure = 'ssl';
\t \t $this->objMailer->Host = "smtp.gmail.com";
\t \t $this->objMailer->Port = 465;
\t \t $this->objMailer->Username = "email here";
\t \t $this->objMailer->Password = "password here";
\t \t $this->objMailer->SetFrom("email here", "name here");
\t \t $this->objMailer->AddReplyTo("email here ", "name here");
\t \t
\t \t
\t \t
\t }
\t public function process($case = null, $array = null) {
\t
\t \t if (!empty($case)) {
\t \t
\t \t \t switch($case) {
\t \t \t \t
\t \t \t \t case 1:
\t \t \t \t
\t \t \t \t // add url to the array
\t \t \t \t $link = "<a href=\"";
\t \t \t \t $link .= SITE_URL.$this->objUrl->href('activate', array('code', $array['hash']));
\t \t \t \t $link .= "\">";
\t \t \t \t $link .= SITE_URL.$this->objUrl->href('activate', array('code', $array['hash']));
\t \t \t \t $link .= "</a>";
\t \t \t \t $array['link'] = $link;
\t \t \t \t
\t \t \t \t $this->objMailer->Subject = "Activate your account";
\t \t \t \t
\t \t \t \t $this->objMailer->MsgHTML($this->fetchEmail($case, $array));
\t \t \t \t $this->objMailer->AddAddress(
\t \t \t \t \t $array['email'],
\t \t \t \t \t $array['first_name'].' '.$array['last_name']
\t \t \t \t);
\t \t \t \t
\t \t \t \t break;
\t \t \t \t
\t \t \t }
\t \t \t
\t \t \t
\t \t \t // send email
\t \t \t if ($this->objMailer->Send()) {
\t \t \t \t $this->objMailer->ClearAddresses();
\t \t \t \t return true;
\t \t \t }
\t \t \t return false;
\t \t \t
\t \t
\t \t }
\t
\t
\t }
\t public function fetchEmail($case = null, $array = null) {
\t
\t \t if (!empty($case)) {
\t \t \t
\t \t \t if (!empty($array)) { \t \t \t
\t \t \t \t foreach($array as $key => $value) {
\t \t \t \t \t ${$key} = $value;
\t \t \t \t } \t \t \t
\t \t \t }
\t \t \t
\t \t \t ob_start();
\t \t \t require_once(EMAILS_PATH.DS.$case.".php");
\t \t \t $out = ob_get_clean();
\t \t \t return $this->wrapEmail($out);
\t \t
\t \t }
\t
\t }
\t public function wrapEmail($content = null) {
\t \t if (!empty($content)) {
\t \t \t return "<div style=\"font-family:Arial,Verdana,Sans-serif;font-size:12px;color:#333;line-height:21px;\">{$content}</div>";
\t \t }
\t }
\t
}
Любая помощь очень ценится
Благодаря
Я пытался изменить код на код ниже, но все это я получаю пустой экран. Я проверил firefox и сообщения об ошибках не отображаются. Может ли кто-нибудь помочь исправить проблему.
Спасибо
<?php
//require_once('PHPMailer_v5.1/PHPMailer.php');
class Email {
\t public $objUrl;
\t //private $objMailer;
\t public function __construct($objUrl = null) {
\t
\t \t $this->objUrl = is_object($objUrl) ? $objUrl : new Url();
\t \t
\t \t $to = "[email protected]";
\t \t $headers = 'MIME-Version: 1.0'."\r\n";
\t \t $headers .= 'Content-type: text/html; charset=iso-8859-1'."\r\n";
\t \t $headers .= "From: [email protected]";
\t \t
\t \t
\t \t
\t }
\t public function process($case = null, $array = null) {
\t
\t \t if (!empty($case)) {
\t \t
\t \t \t switch($case) {
\t \t \t \t
\t \t \t \t case 1:
\t \t \t \t
\t \t \t \t // add url to the array
\t \t \t \t $link = "<a href=\"";
\t \t \t \t $link .= SITE_URL.$this->objUrl->href('activate', array('code', $array['hash']));
\t \t \t \t $link .= "\">";
\t \t \t \t $link .= SITE_URL.$this->objUrl->href('activate', array('code', $array['hash']));
\t \t \t \t $link .= "</a>";
\t \t \t \t $array['link'] = $link;
\t \t \t \t
\t \t \t \t $subject = "Activate your account";
\t \t \t \t
\t \t \t \t $message($this->fetchEmail($case, $array));
\t \t \t \t $address(
\t \t \t \t \t $array['email'],
\t \t \t \t \t $array['first_name'].' '.$array['last_name']
\t \t \t \t);
\t \t \t \t
\t \t \t \t break;
\t \t \t \t
\t \t \t }
\t \t \t
\t \t \t
\t \t \t // send email
\t \t \t if ($send()) {
\t \t \t \t $this->ClearAddresses();
\t \t \t \t return true;
\t \t \t }
\t \t \t return false;
\t \t \t
\t \t
\t \t }
\t
\t
\t }
\t public function fetchEmail($case = null, $array = null) {
\t
\t \t if (!empty($case)) {
\t \t \t
\t \t \t if (!empty($array)) { \t \t \t
\t \t \t \t foreach($array as $key => $value) {
\t \t \t \t \t ${$key} = $value;
\t \t \t \t } \t \t \t
\t \t \t }
\t \t \t
\t \t \t ob_start();
\t \t \t require_once(EMAILS_PATH.DS.$case.".php");
\t \t \t $out = ob_get_clean();
\t \t \t return $this->wrapEmail($out);
\t \t
\t \t }
\t
\t }
\t public function wrapEmail($content = null) {
\t \t if (!empty($content)) {
\t \t \t return "<div style=\"font-family:Arial,Verdana,Sans-serif;font-size:12px;color:#333;line-height:21px;\">{$content}</div>";
\t \t }
\t }
\t
}
Я голосующий, чтобы закрыть этот вопрос как не по теме, потому что Stack Overflow это * не * перевод кода. Вы должны попытаться ** написать код самостоятельно **, а затем, если у вас есть проблема, вы можете ** опубликовать то, что вы пробовали **, с ** ясным объяснением того, что не работает **. –