PHP

Aus brainelectronics Wiki
Wechseln zu: Navigation, Suche

PHP Mail

Installation

PHP Mail

   $ sudo pear install Mail
   $ sudo pear install Net_SMTP

Pfad definieren

Mittels CTRL+W kann im Terminal Nano gesucht werden

   $ sudo nano /etc/php5/apache2/php.ini 
[mail function]
sendmail_path = /usr/sbin/sendmail
 

Test

<?php
 require_once "Mail.php";

 $from = "Vorname Name <name@domain.de>";
 $to = "Klaus Reci <receive@domain.com>";
 $subject = "Hi! from smtp";
 $body = "Hi,\n laueft?";

 $username = "smtp_user_name";
 $password = "your-password";

 $host = "your.host.com"; # STRATO "ssl://smtp.strato.de"
 $port = "465";

 $headers = array ('From' => $from,
   'To' => $to,
   'Subject' => $subject);
 $smtp = Mail::factory('smtp',
   array ('host' => $host,
     'port' => $port,
     'auth' => true,
     'username' => $username,
     'password' => $password));

 $mail = $smtp->send($to, $headers, $body);

 if (PEAR::isError($mail)) {
   echo("<p>" . $mail->getMessage() . "</p>");
  } else {
   echo("<p>Message successfully sent!</p>");
  }
 ?>