Ciao ragazzi, ho appena iniziato a studiare la programmazione OOP...
Sto cercando di trasformare la mia piccola applicazione sendmail in una classe, ma mi trovo bloccato da un errore mai riscontrato prima :
Warning: mail(): SMTP server response: 550 Address '<mymail@localhost>' not known here. in C:\xampp\htdocs\...\sendMail.class.php on line xx
Sicuramente avrò scritto qualche cavolata
sapreste darmi un aiutino?
Grazie in anticipo, di seguito il codice.
sendMail.class.php
Codice PHP:
class sendMail {
public $eol = "\r\n";
public $form = '';
//public $recipient = 'info@mysite.com'; // recipient adress
public $recipient = ''; // testing recipient adress
public $object = '';
public $headers = '';
public $body = '';
//public $mittente = $settings['mail'];
public $name = '';
public $surname = '';
public $company = '';
public $address = '';
public $phone = '';
public $fax = '';
public $mail = '';
public $message = '';
public $from = '';
function __construct($infoMail) {
$this->recipient = $infoMail;
}
function templateMail() {
if ($this->company!=''){$this->from = ' da '.$this->company;}
$this->object = "E-Mail dal sito mysite.com - ".$this->from.' ('.$this->name.' '.$this->surname.')'; // object of the E-Mail
$this->headers = "From: ".$this->name.' '.$this->surname.' '."<".$this->mail.">".$this->eol;
$this->headers .= "Reply-To: ".$this->name.' '.$this->surname.' '."<".$this->mail.">".$this->eol; // Reply-To info. Name and E-Mail
$this->headers .= "Return-Path: ".$this->name.' '.$this->surname.' '."<".$this->mail.">".$this->eol;
$this->headers .= "Message-ID: <".time()."-".$this->mail.">".$this->eol; // Info to help avoid antispam filters
$this->headers .= "X-Mailer: PHP v".phpversion().$this->eol;
$this->body = utf8_decode(trim(stripslashes($this->eol.$this->eol.
'Nome e cognome : '.$this->name.' '.$this->surname.$this->eol.
'Azienda : '.$this->company.$this->eol.
'Telefono : '.$this->phone.$this->eol.
'Fax : '.$this->fax.$this->eol.
'E-mail : '.$this->mail)).$this->eol);
$this->body .= $this->eol;
$this->body .= '--------------------------------------------------------------------------'.$this->eol;
$this->body .= $this->eol;
if (mail($this->recipient, $this->object, $this->body, $this->headers)) {
echo '<h1>Success!</h1>';
echo '
';
echo '
Name : ' . $this->name;
echo '
Surname : ' . $this->surname;
echo '
Company : ' . $this->company;
echo '
Phone : ' . $this->phone;
echo '
Fax : ' . $this->fax;
echo '
Mail : ' . $this->mail;
echo '
Message : ' . $this->message;
echo '</p>';
}
else { echo '<h1>Fail!</h3>'; }
}
}
send-test.php
Codice PHP:
include '../common/sendMail.class.php';
$obj = new sendMail($settings['mail']); // $settings['mail'] viene letto correttamente, preso da file con settings vari
$obj->name = $_POST['name'];
$obj->surname = $_POST['surname'];
$obj->company = $_POST['company'];
$obj->phone = $_POST['phone'];
$obj->fax = $_POST['fax'];
$obj->mail = $_POST['mail'];
$obj->message = $_POST['message'];
$obj->templateMail();